unity第一人稱
using UnityEngine; using System.Collections; public class FirstView : MonoBehaviour { //方向靈敏度 public float sensitivityX = 10F; public float sensitivityY = 10F; //上下最大視角(Y視角) public float minimumY = -60F; public float maximumY = 60F; float rotationY = 0F; voidUpdate () { //根據鼠標移動的快慢(增量), 獲得相機左右旋轉的角度(處理X) float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX; //根據鼠標移動的快慢(增量), 獲得相機上下旋轉的角度(處理Y) rotationY += Input.GetAxis("Mouse Y") * sensitivityY; //角度限制. rotationY小於min,返回min. 大於max,返回max. 否則返回valuerotationY = Mathf.Clamp (rotationY, minimumY, maximumY); //總體設置一下相機角度 transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0); } void Start () { // Make the rigid body not change rotation if (rigidbody) rigidbody.freezeRotation= true; } }
using UnityEngine;using System.Collections;
public class FirstView : MonoBehaviour {
//方向靈敏度public float sensitivityX = 10F; public float sensitivityY = 10F; //上下最大視角(Y視角)public float minimumY = -60F;public float maximumY = 60F;float rotationY = 0F;void Update (){//根據鼠標移動的快慢(增量), 獲得相機左右旋轉的角度(處理X)float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;//根據鼠標移動的快慢(增量), 獲得相機上下旋轉的角度(處理Y)rotationY += Input.GetAxis("Mouse Y") * sensitivityY;//角度限制. rotationY小於min,返回min. 大於max,返回max. 否則返回value rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);//總體設置一下相機角度transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0); }void Start (){// Make the rigid body not change rotationif (rigidbody)rigidbody.freezeRotation = true;}}
unity第一人稱