So I am trying to make an object move backwards in C#:
void Update () {
transform.Translate(Vector3.back * Time.deltaTime, Space.World);
}
However, I only want it to move backwards for a certain amount of time. How would I go about this? BTW I am a massive newbie with this stuff if you couldn’t already tell.
DylanW
October 15, 2013, 4:10am
2
Here you go, please read the comments:
C#:
float timeLimit = 10.0f; // 10 seconds.
void Update()
{
// translate object for 10 seconds.
if(timeLimit > 1) {
// Decrease timeLimit.
timeLimit -= Time.deltaTime;
// translate backward.
transform.Translate(Vector3.back * Time.deltaTime, Space.World);
Debug.Log(timeLimit);
}
}
Javascript:
var timeLimit : float = 10.0f; // 10 seconds.
function Update()
{
// translate object for 10 seconds.
if(timeLimit > 1){
// Decrease timeLimit.
timeLimit -= Time.deltaTime;
// translate backward.
transform.Translate(Vector3.back * Time.deltaTime, Space.World);
Debug.Log(timeLimit);
}
}