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 }

 

转载于:https://www.cnblogs.com/heizai/p/6135499.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值