1 public class CameraMove : MonoBehaviour { 2 private Camera c; 3 private float rotateSpeed = 10; 4
5 private void Start() { 6 c = this.GetComponent<Camera>(); 7
8 } 9
10 private void Update() {
//獲取虛擬按鍵 11 float mouseX = Input.GetAxis("Mouse X"); 12 /*
這里有個錯誤,rotateSpeed參數無效,實際旋轉速度由
13 this.transform.RotateAround()第三個參數決定
*/
//勻速旋轉 14 mouseX *= rotateSpeed *Time.deltaTime; 15
16 //建議使用本地坐標X,世界坐標Y 17 //模擬飛飛鼠標右鍵按住不放旋轉,即圍繞角色上下左右旋轉 18 //RotateAround(注視誰,移動坐標,移動多少米)
19 if (Input.GetMouseButton(1)) {
//左右環繞旋轉鏡頭 20 this.transform.RotateAround
(this.transform.parent.position, new Vector3(0, mouseX, 0), 10); 21 } 22
23 } 24 }
以角色為軸心點,圍繞旋轉,注意相機位置