首页 > 代码库 > Unity全视角跟随鼠标右键转换视角实现——研究笔记
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全视角跟随鼠标右键转换视角实现——研究笔记
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。