1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
C#语言: 
 
01 
using 
UnityEngine;
02 [RequireComponent( 
typeof
( Camera ) )]
03 
public 
class 
ThirdPersonCamera : MonoBehaviour
04 {
05     
// Attribute ------------------------------------------------------------------------
06     
public 
Transform    follow;
07     
public     
float     
m_fDistance     = 7.0f;
08     
public     
float     
m_fXSpeed     = 350.0f;
09     
public     
float     
m_fYMinLimit     = 0.1f;
10     
public     
float     
m_fYMaxLimit     = 89.9f;
11     
private     
float     
m_fXRot     = 0.0f;
12     
public     
float     
m_fYRot     = 0.0f;
13     
public 
float 
speed=5.0f;
14     
void 
Start(){
15     follow=follow?follow:GameObject.Find(
"Player"
).transform;
16     }
17     
void 
LateUpdate(){
18         
if
(Input.GetMouseButton(0)){
19             m_fXRot += Input.GetAxis(
"Mouse X"
)/10.0f * m_fXSpeed;
20             m_fYRot -= Input.GetAxis(
"Mouse Y"
)/10.0f * m_fXSpeed; 
21         }
22         m_fYRot = Mathf.Clamp(m_fYRot,m_fYMinLimit, m_fYMaxLimit);
23         Vector3 negDistance= 
new 
Vector3(0.0f, 0.0f, -m_fDistance);
24         
//transform.rotation = Quaternion.Lerp(transform.rotation,Quaternion.Euler(m_fYRot, m_fXRot, 0),Time.deltaTime*speed);
25         transform.rotation =Quaternion.Euler(m_fYRot, m_fXRot, 0);
26         transform.position = transform.rotation * negDistance + follow.position;
27     }
28 }
   


版权声明:本文为xiaonan7147原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/xiaonan7147/article/details/41806181