Unity3d input.getaxis返回-默认情况下为1 unity 5.3.0 使用UnityEngine; 使用系统集合; 公共类玩家:单一行为{ 公共浮子速度=8.0f; 公共浮点数maxVelocity=3.0f; //用于初始化 无效开始(){ } //每帧调用一次更新 无效更新(){ 浮动力=0.0f; float-velocity=Mathf.Abs(GetComponent().velocity.x); float h=Input.GetAxis(“水平”);//仅沿x轴获取输入 调试日志(h); 如果(h>0){ if(速度
这里我的Unity3d input.getaxis返回-默认情况下为1 unity 5.3.0 使用UnityEngine; 使用系统集合; 公共类玩家:单一行为{ 公共浮子速度=8.0f; 公共浮点数maxVelocity=3.0f; //用于初始化 无效开始(){ } //每帧调用一次更新 无效更新(){ 浮动力=0.0f; float-velocity=Mathf.Abs(GetComponent().velocity.x); float h=Input.GetAxis(“水平”);//仅沿x轴获取输入 调试日志(h); 如果(h>0){ if(速度,unity3d,unityscript,unity3d-2dtools,unity5.3,Unity3d,Unityscript,Unity3d 2dtools,Unity5.3,这里我的h值始终返回-1,即使我没有按任何右/左键 有人能指出我的问题吗?Input.GetAxis(“水平”)从范围-1返回值;1用于操纵杆或其他控制器。请检查您的计算机是否没有任何连接。例如,它可以是赛车 using UnityEngine; using System.Collections; public class Player : MonoBehaviour { public float speed = 8.0f; public float maxVelocity =3.0f;
h
值始终返回-1
,即使我没有按任何右/左键
有人能指出我的问题吗?Input.GetAxis(“水平”)
从范围-1返回值;1用于操纵杆或其他控制器。请检查您的计算机是否没有任何连接。例如,它可以是赛车
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));
}
}