我在 YouTube 上關注關于運動的 C# 教程,但代碼不起作用我試圖找到問題,但我什么也沒找到。有人可以幫幫我嗎?
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
CharacterController ch;
void Start()
{
ch = GetComponent<CharacterController>();
}
void Update()
{
float x = input.GetAxis('Horizontal') * moveSpeed * Time.deltaTime;
float z = input.GetAxis('Vertical') * moveSpeed * Time.deltaTime;
ch.Move(x,0, z);
}
}
我試著做運動
uj5u.com熱心網友回復:
根據檔案(https://docs.unity3d.com/ScriptReference/CharacterController.Move.html),(x,y,z)沒有過載。
嘗試像這樣移動:
float frameSpeed = moveSpeed * Time.deltaTime;
ch.Move(new Vector3(
Input.GetAxis("Horizontal") * frameSpeed,
0.0f,
Input.GetAxis("Vertical") * frameSpeed);
此外,輸入是輸入,字串需要“”,而不是“”(用于字符)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/523514.html
標籤:C#unity3d
