標籤:

滑鼠控制視野腳本

public class MouseLook1 : MonoBehaviour {

//靈敏度

public float sensitivity = 2.0f;

public float MinmumX = -90f;

public float MaxmumX = 90f;

//緩動速度

public float smooth = 5;

Transform m_cameraTransform;

//記錄目標旋轉角

private Quaternion parentTargeRot;

private Quaternion cameraTargetRot;

private void Start(){

parentTargeRot = transform.localRotation;

cameraTargetRot = Camera.main.transform.localRotation;

}

// Update is called once per frame

void Update () {

float yRot = Input.GetAxis("Mouse X") * sensitivity;

float xRot = Input.GetAxis("Mouse Y") * sensitivity;

parentTargeRot *= Quaternion.Euler(0, yRot, 0);

cameraTargetRot *= Quaternion.Euler(xRot, 0, 0);

transform.localRotation = Quaternion.Slerp(transform.localRotation, parentTargeRot, Time.deltaTime * smooth);

Camera.main.transform.localRotation = Quaternion.Slerp(Camera.main.transform.localRotation, cameraTargetRot, Time.deltaTime * smooth);

}

}


推薦閱讀:

會AE的你,想要提高工作效率嗎?
魯德——Python開發性能測試腳本
腳本對短視頻的作用有多大?原來不賺錢是因為一開始就錯了!
免費:3dmax不基於UV遮罩插件腳本
Approach - GMS中常用腳本介紹(1/5)

TAG:腳本 |