- Home /
Objects moving faster after time
Hi everyone. First of all, sorry for my bad english! So I make a Infinite 2d game. In this game the player dodges objects. The player doesn't moves all the other objects moves. Now I want that the objects moves faster after 20 seconds. I make two scripts but they didn't work!? Here is the first script:
function Start() {
InvokeRepeating("Every20Seconds", 20.0, 20.0);
}
var speed : = 4.0;
var addspeed = 0.5;
function Every20Seconds() {
speed = speed + addspeed;
}
function Update() {
transform.Translate(Vector3.down * speed * Time.deltaTime);
}
and here is the other script:
var speed = 4.0;
var addspeed = 0.5;
var timeDelay = 25;
function Start() {
while (true) {
yield WaitForSeconds(timeDelay);
speed= speed + addspeed;
}
}
function Update ()
{
transform.Translate(Vector3.up * speed * Time.deltaTime);
}
Thank you for your help!
Comment
Answer by jokim · Aug 20, 2014 at 03:32 PM
I'd avoid using start as a timer function. I'd move it all down to the update one.
Also, you should get a timer in, which you could have more control over... such as pausing it.
Here's what I have in mind :
var speed = 4.0;
var addspeed = 0.5;
var timer =0;
function Update ()
{
timer += Time.deltaTime;
if (timer >= 20)
{
timer = 0;
speed += addSpeed;
}
transform.Translate(Vector3.up * speed * Time.deltaTime);
}