2015-12-19 3 views
2
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, даже если я не нажав любой из правой/левой клавиши.input.getaxis возвращение -1 по умолчанию единицы 5.3.0

Может ли кто-нибудь указать нашу проблему здесь?

ответ

2

Input.GetAxis ("Horizontal") возвращает значение из диапазона -1; 1 для вашего джойстика или другого контроллера. Убедитесь, что у вас нет подключения к компьютеру. Например, это может быть гоночное колесо.