Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我的球员是心灵传送,而不是顺利移动?_C#_Unity3d - Fatal编程技术网

C# 为什么我的球员是心灵传送,而不是顺利移动?

C# 为什么我的球员是心灵传送,而不是顺利移动?,c#,unity3d,C#,Unity3d,我不知道为什么,但是我的球员移动不是很平稳,而是有点像心灵传送,但是我必须多次按键才能移动他几英寸,我无法握住按键让他行走。这是我的密码: public class player : MonoBehaviour { private Rigidbody _rigidbody; private void Awake() => GetComponent< Rigidbody> (); private void Start() { } void Update()

我不知道为什么,但是我的球员移动不是很平稳,而是有点像心灵传送,但是我必须多次按键才能移动他几英寸,我无法握住按键让他行走。这是我的密码:

public class player : MonoBehaviour
{
private Rigidbody _rigidbody;

private void Awake() => GetComponent< Rigidbody> ();


private void Start()
{
  

 

}

void Update()
{

  if (_WalkRight) 
   transform.position += Time.deltaTime * Walk_speed * Vector3.right;

  if (_WalkLeft) 
   transform.position += Time.deltaTime * Walk_speed * Vector3.left;

  if (_WalkUp) 
   transform.position += Time.deltaTime * Walk_speed * Vector3.forward;

  if (_WalkDown) 
   transform.position += Time.deltaTime * Walk_speed * Vector3.back;

  
}

[SerializeField] private float Walk_speed = 30f;
[SerializeField] private float Run_speed = 60f;
private bool _WalkRight => Input.GetKeyDown(KeyCode.D);
private bool _WalkLeft => Input.GetKeyDown(KeyCode.A) ;
private bool _WalkUp => Input.GetKeyDown(KeyCode.W) ;
private bool _WalkDown => Input.GetKeyDown(KeyCode.S);


}
公共类玩家:单行为
{
私人刚体;
私有void Awake()=>GetComponent();
私有void Start()
{
}
无效更新()
{
如果(右)
transform.position+=Time.deltaTime*行走速度*矢量3.right;
如果(左)
transform.position+=Time.deltaTime*行走速度*向量3.left;
如果(_WalkUp)
transform.position+=Time.deltaTime*行走速度*矢量3.forward;
如果(_巡检)
transform.position+=Time.deltaTime*行走速度*矢量3.back;
}
[现场]私人浮子行走速度=30f;
[SerializeField]专用浮球运行速度=60f;
私有bool\u WalkRight=>Input.GetKeyDown(KeyCode.D);
私有bool\u WalkLeft=>Input.GetKeyDown(KeyCode.A);
私有bool\u WalkUp=>Input.GetKeyDown(KeyCode.W);
私有bool\u WalkDown=>Input.GetKeyDown(KeyCode.S);
}
有人能指出我做错了什么吗?另外,我知道变量通常出现在代码的开头,我会修正它。

输入。如果在下一帧按住它,GetKeyDown(KeyCode)
不会返回
true
,也就是说,您需要重复按所需的键


改用
Input.GetKey(KeyCode)

谢谢你,伙计,你是个救生员!它现在工作得很好