Unity3D之Camera跟随鼠标移动,右键显示或隐藏鼠标

using UnityEngine;
using System.Collections;

public class FreeCamera : MonoBehaviour {

    private float mouseX;
    private float mouseY;
    private bool isShow;

    public float rotateSpeed;//旋转速度

    void Start () {
        isShow = false;
        UnityEngine.Cursor.visible = false;
    }
    
    // Update is called once per frame
    void Update () {
        transform.localEulerAngles = new Vector3 (transform.localEulerAngles.x,transform.localEulerAngles.y,0);
        mouseX = Input.GetAxisRaw ("Mouse X");
        mouseY = Input.GetAxisRaw ("Mouse Y");
        transform.Rotate (Vector3.Slerp(Vector3.zero ,new Vector3(-mouseY,mouseX,0),rotateSpeed*Time.deltaTime));
        if(Input.GetMouseButtonDown(1)){
            if (isShow == false) {
                UnityEngine.Cursor.visible = true;
                isShow = true;
            } else {
                UnityEngine.Cursor.visible = false;
                isShow = false;
            }
        }
    }
}

 

posted on 2016-10-19 13:20  3137102247  阅读(469)  评论(0编辑  收藏  举报

导航