-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThirdPersonCamera.cs
93 lines (75 loc) · 2.48 KB
/
ThirdPersonCamera.cs
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// Unityちゃん用の三人称カメラ
//
// 2013/06/07 N.Kobyasahi
//
using UnityEngine;
using System.Collections;
public class ThirdPersonCamera : MonoBehaviour
{
public float smooth = 3f; // カメラモーションのスムーズ化用変数
Transform standardPos; // the usual position for the camera, specified by a transform in the game
Transform frontPos; // Front Camera locater
Transform jumpPos; // Jump Camera locater
// スムーズに繋がない時(クイック切り替え)用のブーリアンフラグ
bool bQuickSwitch = false; //Change Camera Position Quickly
void Start()
{
// 各参照の初期化
standardPos = GameObject.Find ("CamPos").transform;
if(GameObject.Find ("FrontPos"))
frontPos = GameObject.Find ("FrontPos").transform;
if(GameObject.Find ("JumpPos"))
jumpPos = GameObject.Find ("JumpPos").transform;
//カメラをスタートする
transform.position = standardPos.position;
transform.forward = standardPos.forward;
}
void FixedUpdate () // このカメラ切り替えはFixedUpdate()内でないと正常に動かない
{
if(Input.GetButton("Fire1")) // left Ctlr
{
// Change Front Camera
//setCameraPositionFrontView();
}
else if(Input.GetButton("Fire2")) //Alt
{
// Change Jump Camera
//setCameraPositionJumpView();
}
else
{
// return the camera to standard position and direction
//setCameraPositionNormalView();
}
setCameraPositionNormalView();
}
void setCameraPositionNormalView()
{
if(bQuickSwitch == false){
// the camera to standard position and direction
transform.position = Vector3.Lerp(transform.position, standardPos.position, Time.fixedDeltaTime * smooth);
transform.forward = Vector3.Lerp(transform.forward, standardPos.forward, Time.fixedDeltaTime * smooth);
}
else{
// the camera to standard position and direction / Quick Change
transform.position = standardPos.position;
transform.forward = standardPos.forward;
bQuickSwitch = false;
}
}
void setCameraPositionFrontView()
{
// Change Front Camera
bQuickSwitch = true;
transform.position = frontPos.position;
transform.forward = frontPos.forward;
}
void setCameraPositionJumpView()
{
// Change Jump Camera
bQuickSwitch = false;
transform.position = Vector3.Lerp(transform.position, jumpPos.position, Time.fixedDeltaTime * smooth);
transform.forward = Vector3.Lerp(transform.forward, jumpPos.forward, Time.fixedDeltaTime * smooth);
}
}