码迷,mamicode.com
首页 > 编程语言 > 详细

unity第一人称

时间:2018-04-03 23:49:13      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:处理   方向   bsp   gpo   ini   amp   body   min   art   

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 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第一人称

标签:处理   方向   bsp   gpo   ini   amp   body   min   art   

原文地址:https://www.cnblogs.com/fengdaren/p/8711479.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!