首先你要新建一個腳本,我這里是用c#,然后編寫下面代碼,最后將寫好的c#腳本附加到主相機上。
using UnityEngine;
using System.Collections;
public class Fashe:MonoBehaviour{
void start(){}
void update(){
float x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;//左右移動
float z = Input.GetAxis("Vertical") * Time.deltaTime * speed;//前后移動
transform.Translate(x,0,z);//相機的移動
//旋轉功能
if (Input.GetKey(KeyCode.Q))//這個 表示如果鍵盤上輸入Q則返回 true
{
transform.Rotate(0, -25 * Time.deltaTime, 0, Space.Self);//transform表示該物體下的transform組件,Rotate()表示旋轉角度,前三個參數表示 X,Y.Z軸上的旋 轉角度,最后一個參數表示圍繞自身旋轉。下面的也是類似!
}
if (Input.GetKey(KeyCode.E))
{
transform.Rotate(0, 25 * Time.deltaTime, 0, Space.Self);
}
//上下移動鏡頭
if (Input.GetKey(KeyCode.H))
{
transform.Translate(0, 3 * Time.deltaTime, 0);
}
if (Input.GetKey(KeyCode.N))
{
transform.Translate(0, -3 * Time.deltaTime, 0);
}
}
}