Как управлять по-разному двумя разными джойстиками(на Canvas) в 3D Unity игре?

365
09 сентября 2017, 23:26

Как присвоить разные функции двум разным джойстикам? И как определить, что это они именно были нажаты. Я попытался перерыть матриал по Touch, fingerId, GetComponent,GetTouch и т.д. + так же смотрел инфу по присвоению id объекту, но мне это не особо помогло, или я просто не смог правильно возпользоваться этой всей информацией. Так или иначе можете помочь, объяснить или дать подсказку, или дать код(может хотя бы кусочек)

Вот стате содержимое моих файлов со скриптами: PlayerController.cs:

using UnityEngine;
using CnControls;
using System;
[RequireComponent(typeof(PlayerMotor))]
public class PlayerController : MonoBehaviour {
    [SerializeField]
    private float speed = 5f;
    [SerializeField]
    private float lookSpeed = 3f;
    private PlayerMotor motor;
    private void Start()
    {
        motor = GetComponent <PlayerMotor> ();
    }

    private void Update()
    {   
        float xMov = CnInputManager.GetAxisRaw("Horizontal");
        float zMov = CnInputManager.GetAxisRaw("Vertical");
        //Input.GetAxisRaw("Vertical");
        Vector3 movHor = transform.right * xMov;
        Vector3 movVer = transform.forward * zMov;
        Vector3 velocity = (movHor + movVer).normalized * speed;
        motor.Move(velocity);
       // float yRot = Input.GetAxisRaw("Mouse X");
        //Vector3 rotation = new Vector3(0f, yRot, 0f) * lookSpeed;
        float yRot = CnInputManager.GetAxisRaw(axisName: "Joystick 2");
        Vector3 rotation = new Vector3(0f, yRot, 0f) * lookSpeed;
        motor.Rotate(rotation);
        // float xRot = Input.GetAxisRaw("Mouse Y"); 
        // Vector3 camRotation = new Vector3(xRot, 0f, 0f) * lookSpeed;
        float xRot = CnInputManager.GetAxisRaw(axisName: "Joystick 2");
        Vector3 camRotation = new Vector3(xRot, 0f, 0f) * lookSpeed;
        motor.RotateCam(camRotation);
    }
}

PlayerMotor.cs:

using UnityEngine;
using CnControls;
[RequireComponent(typeof(Rigidbody))]
public class PlayerMotor : MonoBehaviour {
    [SerializeField]
    private Camera cam;
    private Rigidbody rb;
    private Vector3 velocity = Vector3.zero;
    private Vector3 rotation = Vector3.zero;
    private Vector3 camRotation = Vector3.zero;
    private void Start()
    {
        rb = GetComponent <Rigidbody> ();
    }
    public void Move(Vector3 _velocity)
    {
        velocity = _velocity;
    }
    public void Rotate(Vector3 _rotaton)
    {
        rotation = _rotaton;
    }
    public void RotateCam(Vector3 _camRotaton)
    {
        camRotation = _camRotaton;
    }
    void FixedUpdate()
    {
        PerformMove();
        PerformRotation();
    }
    void PerformMove()
    {
        if (velocity != Vector3.zero)
            rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
    }
    void PerformRotation()
    {
        rb.MoveRotation(rb.rotation * Quaternion.Euler(rotation));
        if (cam != null)
            cam.transform.Rotate(-camRotation);
    }
}

Стате, компоненты(два джойстика и кнопка) из asset store я использую - CnControls

Очень благодарен заранее.

P.S. Я - глубокий новичок в Unity и С#, так пожалуйста, сильно не злитесь, если вопрос глупый) Ах и стате, игра - 3D шутер, если её так можно назвать)

READ ALSO
Использование Array.Sort в индексаторе

Использование Array.Sort в индексаторе

ЗдравствуйтеУ меня есть индексатор типа Array, объявленный в классе HomeLibrary

261
Как изменить fingerprint браузера

Как изменить fingerprint браузера

В программе используется CefSharpСтоит задача менять fingerprint браузера

456
Способы создания объектов в C#

Способы создания объектов в C#

Я знаю 1 способ создать объекта в C#:

352