Stopping a bit of script once it reaches certain number.

So I made this script for acceleration:

var speed: 0.3

if(GetDownKey(KeyCode.UpArrow))

{

transform.Translate (speed += 2.0 * Time.deltaTime))

}

Basically I want the transform.Translate bit to stop once the speed reaches 153.6. How do I do this?

2 Answers

2

with an if statement?

if ( speed < 153.6 ) Translate

try this:
if(GetDownKey(KeyCode.UpArrow) && speed < 153.6)