Created
October 8, 2018 18:49
-
-
Save thelucre/0de9dc4d02c898bfbec89f177b04895c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
namespace UnityStandardAssets.Utility | |
{ | |
public class AutoMoveAndRotate : MonoBehaviour | |
{ | |
public Vector3andSpace moveUnitsPerSecond; | |
public Vector3andSpace rotateDegreesPerSecond; | |
public bool ignoreTimescale; | |
private float m_LastRealTime; | |
private void Start() | |
{ | |
m_LastRealTime = Time.realtimeSinceStartup; | |
} | |
// Update is called once per frame | |
private void Update() | |
{ | |
float deltaTime = Time.deltaTime; | |
if (ignoreTimescale) | |
{ | |
deltaTime = (Time.realtimeSinceStartup - m_LastRealTime); | |
m_LastRealTime = Time.realtimeSinceStartup; | |
} | |
transform.Translate(moveUnitsPerSecond.value*deltaTime, moveUnitsPerSecond.space); | |
transform.Rotate(rotateDegreesPerSecond.value*deltaTime, moveUnitsPerSecond.space); | |
} | |
[Serializable] | |
public class Vector3andSpace | |
{ | |
public Vector3 value; | |
public Space space = Space.Self; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment