Заменить ввод.Получить ось (горизонтальная) с сенсорным вводом - Unity ответы - PullRequest
0 голосов
/ 09 мая 2019

В публичном void Update () мне нужно изменить float x = maxAngle * Input.GetAxis ("Horizontal");от клавиатуры Axis до мобильной оси Я имею в виду этот код, я могу поворачивать колеса только вправо и влево, используя оси клавиатуры, но я хочу иметь возможность касаться правой половины подвижного экрана, чтобы переместить его вправо, и коснутьсялевую половину мобильного экрана, чтобы переместить его влево.

с использованием UnityEngine;using System.Collections;

открытый класс RearWheelDrive: MonoBehaviour {

private WheelCollider[] wheels;
public float moveSpeed;
[SerializeField]
//private float angleSpeed;

public float maxAngle = 30;
public float maxTorque = 300;
public GameObject wheelShape;

// here we find all the WheelColliders down in the hierarchy
public void Start()
{
    wheels = GetComponentsInChildren<WheelCollider>();

    for (int i = 0; i < wheels.Length; ++i)
    {
        var wheel = wheels[i];

        // create wheel shapes only when needed
        if (wheelShape != null)
        {
            var ws = GameObject.Instantiate(wheelShape);
            ws.transform.parent = wheel.transform;
        }
    }
}

// this is a really simple approach to updating wheels
// here we simulate a rear wheel drive car and assume that the car is perfectly symmetric at local zero
// this helps us to figure our which wheels are front ones and which are rear
public void Update()
{

    float x = maxAngle * Input.GetAxis("Horizontal");
    float torque = maxTorque * moveSpeed;


    foreach (WheelCollider wheel in wheels)
    {
        // a simple car where front wheels steer while rear ones drive
        if (wheel.transform.localPosition.z > 0)
            wheel.steerAngle = x;


        wheel.motorTorque = torque;

        // update visual wheels if any
        if (wheelShape)
        {
            Quaternion q;
            Vector3 p;
            wheel.GetWorldPose(out p, out q);

            // assume that the only child of the wheelcollider is the wheel shape
            Transform shapeTransform = wheel.transform.GetChild(0);
            shapeTransform.position = p;
            shapeTransform.rotation = q;
        }

    }


}

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...