t1 / TFDContents / Assets / KinectDemos / SpeechRecognitionDemo / Scripts / ThirdPersonCamera.cs @ 3
이력 | 보기 | 이력해설 | 다운로드 (1.4 KB)
1 |
using UnityEngine; |
---|---|
2 |
using System.Collections; |
3 |
|
4 |
public class ThirdPersonCamera : MonoBehaviour |
5 |
{ |
6 |
[Tooltip("Smoothing factor of camera motion.")] |
7 |
public float smooth = 3f; // a public variable to adjust smoothing of camera motion |
8 |
|
9 |
private Transform standardPos; // the usual position for the camera, specified by a transform in the game |
10 |
private Transform lookAtPos; // the position to move the camera to when using head look |
11 |
|
12 |
|
13 |
void Start() |
14 |
{ |
15 |
// initialising references |
16 |
standardPos = GameObject.Find ("CamPos").transform; |
17 |
|
18 |
if(GameObject.Find ("LookAtPos")) |
19 |
lookAtPos = GameObject.Find ("LookAtPos").transform; |
20 |
} |
21 |
|
22 |
void FixedUpdate () |
23 |
{ |
24 |
// if we hold Alt |
25 |
if(Input.GetButton("Fire2") && lookAtPos) |
26 |
{ |
27 |
// lerp the camera position to the look at position, and lerp its forward direction to match |
28 |
transform.position = Vector3.Lerp(transform.position, lookAtPos.position, smooth > 0f ? Time.deltaTime * smooth : 1f); |
29 |
transform.forward = Vector3.Lerp(transform.forward, lookAtPos.forward, smooth > 0f ? Time.deltaTime * smooth : 1f); |
30 |
} |
31 |
else |
32 |
{ |
33 |
// return the camera to standard position and direction |
34 |
transform.position = Vector3.Lerp(transform.position, standardPos.position, smooth > 0f ? Time.deltaTime * smooth : 1f); |
35 |
transform.forward = Vector3.Lerp(transform.forward, standardPos.forward, smooth > 0f ? Time.deltaTime * smooth : 1f); |
36 |
} |
37 |
|
38 |
} |
39 |
} |