我從Youtube Unity教程視頻複製了這段代碼,我無法弄清楚它有什麼問題。統一輪換不能在Y軸上工作
當我一起玩遊戲時,我試圖用我的鼠標查找它試圖阻止我這樣做。
using UnityEngine;
using System.Collections;
public class FirstPersonController : MonoBehaviour {
public float movementSpeed = 5.0f;
float verticalRotation = 0;
public float upDownRange = 60.0f;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
//Rotation
float rotLeftRight = Input.GetAxis("Mouse X");
transform.Rotate(0, rotLeftRight, 0);
verticalRotation = Input.GetAxis("Mouse Y");
verticalRotation = Mathf.Clamp(verticalRotation, -upDownRange, upDownRange);
Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);
//Movement
float forwardSpeed = Input.GetAxis ("Vertical") * movementSpeed;
float sideSpeed = Input.GetAxis("Horizontal") * movementSpeed;
Vector3 speed = new Vector3 (sideSpeed, 0, forwardSpeed);
speed = transform.rotation * speed;
CharacterController cc = GetComponent<CharacterController>();
cc.SimpleMove (speed);
}
}
我想你最好問** ** Youtube Unity教程視頻**的作者。 http://stackoverflow.com/help/how-to-ask – zwcloud
它只是我還是他從不分配Y旋轉? –
@Wheremy如果你的問題已經得到解答,一定要接受幫助你的答案。 – Alox