using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
private Vector3 input;
void Update () {
input = new Vector3(Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
rigidbody.AddForce(input * moveSpeed);
}
}
答案 0 :(得分:0)
从Unity 5开始UnityEngine.Component.rigibody
已被弃用,使用它会导致编译错误。相反,您需要使用GetComponent<Rigidbody>()
。因此,在您的情况下,您的代码将如下所示:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
private Vector3 input;
void Update ()
{
input = new Vector3(Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
GetComponent<Rigidbody>().AddForce(input * moveSpeed);
}
}