【问题标题】:input.getaxis returning -1 by default unity 5.3.0input.getaxis 默认返回 -1 unity 5.3.0
【发布时间】:2015-12-19 21:24:18
【问题描述】:
using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {

public float speed = 8.0f;
public float maxVelocity =3.0f;


// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

    float force = 0.0f;
    float velocity = Mathf.Abs (GetComponent<Rigidbody2D>().velocity.x);

    float h = Input.GetAxis ("Horizontal"); //getting input along x-axis only

    Debug.Log (h);

        if (h > 0) {
            if (velocity < maxVelocity) {
                force = speed;
            }
            Vector3 scale = transform.localScale;
            scale.x = 1;
            transform.localScale = scale;

        } else if (h < 0) {

            if (velocity < maxVelocity) {
                force = -speed;
            }

            Vector3 scale = transform.localScale;
            scale.x = -1;
            transform.localScale = scale;
        }

        GetComponent<Rigidbody2D>().AddForce (new Vector2 (force, 0));


    }
}

这里我的h 值总是返回-1,即使我没有按任何左右键。

有人可以在这里指出我们的问题吗?

【问题讨论】:

    标签: unity3d unityscript unity3d-2dtools unity5.3


    【解决方案1】:

    Input.GetAxis ("Horizontal") 为您的操纵杆或其他控制器返回 -1;1 范围内的值。请检查您的计算机是否未连接任何设备。例如,它可以是赛车轮。

    【讨论】:

      猜你喜欢
      • 2013-12-17
      • 1970-01-01
      • 2019-06-08
      • 1970-01-01
      • 2022-08-13
      • 2021-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多