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 }