1 using System;
2 using
UnityEngine;
3
4 namespace
UnityStandardAssets.Utility
5 {
6     
public class AutoMoveAndRotate : MonoBehaviour
7     {
8         
public Vector3andSpace moveUnitsPerSecond;
9         
public Vector3andSpace rotateDegreesPerSecond;
10         
public bool ignoreTimescale;
11         
private float m_LastRealTime;
12
13
14         
private void Start()
15         {
16             m_LastRealTime = Time.realtimeSinceStartup;
17         }
18
19
20         
// Update is called once per frame
21         
private void Update()
22         {
23             
float deltaTime = Time.deltaTime;
24             
if (ignoreTimescale)
25             {
26                 deltaTime = (Time.realtimeSinceStartup - m_LastRealTime);
27                 m_LastRealTime = Time.realtimeSinceStartup;
28             }
29             transform.Translate(moveUnitsPerSecond.
value*deltaTime, moveUnitsPerSecond.space);
30             transform.Rotate(rotateDegreesPerSecond.
value*deltaTime, moveUnitsPerSecond.space);
31         }
32
33
34         
[Serializable]
35         
public class Vector3andSpace
36         {
37             
public Vector3 value;
38             
public Space space = Space.Self;
39         }
40     }
41 }


Xem tìm kiếm...