Unity全视角跟随鼠标右键转换视角实现——研究笔记
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity全视角跟随鼠标右键转换视角实现——研究笔记相关的知识,希望对你有一定的参考价值。
1 using UnityEngine; 2 using System.Collections; 3 4 public class CameraMove : MonoBehaviour 5 { 6 public Transform m_Player; 7 public float m_RotaSpeed = 2; 8 public float m_Slow = 5f; 9 10 private bool m_isAnXia = false; 11 private Vector3 m_xdPos; 12 13 void Start () 14 { 15 m_xdPos = this.transform.position - m_Player.position; 16 } 17 18 void Update () 19 { 20 Move(); 21 Rote(); 22 } 23 24 void Move() 25 { 26 this.transform.position = m_Player.position + m_xdPos; 27 } 28 29 void Rote() 30 { 31 if (Input.GetMouseButtonDown(1)) 32 { 33 m_isAnXia = true; 34 } 35 if (Input.GetMouseButtonUp(1)) 36 { 37 m_isAnXia = false; 38 } 39 if (m_isAnXia) 40 { 41 this.transform.RotateAround(m_Player.position, Vector3.up, Input.GetAxis("Mouse X") * m_RotaSpeed); 42 var pos = this.transform.position; 43 var rota = this.transform.rotation; 44 this.transform.RotateAround(m_Player.position, this.transform.right, Input.GetAxis("Mouse Y") * -m_RotaSpeed); 45 var x = this.transform.eulerAngles.x; 46 if (x < 10 || x > 80) 47 { 48 this.transform.position = pos; 49 this.transform.rotation = rota; 50 } 51 52 m_xdPos = this.transform.position - m_Player.position; 53 } 54 } 55 }
以上是关于Unity全视角跟随鼠标右键转换视角实现——研究笔记的主要内容,如果未能解决你的问题,请参考以下文章
unity3d转换怎样调视角?原本右键可以调视角,但现在它只能调整画面的位置了,怎样改回来?