annotate Chapter5/Assets/SimpleCloudSystem by RM/SceneComponents/Standard Assets/Scripts/Camera Scripts/SmoothLookAt.js @ 2:fdab88fc2cb9

add game projects
author Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
date Fri, 17 Jul 2015 23:14:45 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 var target : Transform;
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 var damping = 6.0;
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 var smooth = true;
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 @script AddComponentMenu("Camera-Control/Smooth Look At")
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 function LateUpdate () {
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 if (target) {
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 if (smooth)
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 {
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 // Look at and dampen the rotation
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 var rotation = Quaternion.LookRotation(target.position - transform.position);
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 }
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 else
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 {
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 // Just lookat
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 transform.LookAt(target);
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 }
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 }
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 }
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 function Start () {
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 // Make the rigid body not change rotation
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 if (GetComponent.<Rigidbody>())
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 GetComponent.<Rigidbody>().freezeRotation = true;
fdab88fc2cb9 add game projects
Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 }