1、player1面板 2、player下加上一个摄像机。 3、脚本如下:
public class player : MonoBehaviour
{
private float moveSpeed;//摄像机的移动速度
public GameObject Eye;
void Start()
{
moveSpeed = -8;
}
Vector3 rot = new Vector3(0, 0, 0);
void Update()
{
//鼠键控制移动
WASD();
if (Input.anyKey)
{
this.GetComponent().constraints = RigidbodyConstraints.FreezeRotation;
}
else
{
this.GetComponent().constraints = RigidbodyConstraints.FreezeAll;
}
}
///
/// 鼠键控制player移动
///
void WASD()
{
if (Input.GetMouseButton(1))
{
if (Input.GetAxis("Mouse X") != 0)
{
//Debug.Log(Input.GetAxis("Mouse X"));