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

Unity全视角跟随鼠标右键转换视角实现——研究笔记

时间:2016-12-05 23:18:27      阅读:376      评论:0      收藏:0      [点我收藏+]

标签:mon   collect   视角   cto   euler   date   update   ram   axis   

 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全视角跟随鼠标右键转换视角实现——研究笔记

标签:mon   collect   视角   cto   euler   date   update   ram   axis   

原文地址:http://www.cnblogs.com/heizai/p/6135499.html

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