Frage

i'm writing here cause i really need your help. i've created this script linked on a gameObject light (Directional).

var time : int= 0;

function Update () {
    time+=1;
    transform.Rotate(time*Time.deltaTime, 0 ,0);
        yield WaitForSeconds(0.2);
    if (time == 360){
        time = 0;
    }
}

when i start the game, the object don't rotate and if i remove the line:

   yield WaitForSeconds(0.2);

the rotation starts slowly then increses its speed until (every 2 rounds) it returns to 0.

War es hilfreich?

Lösung

Jerdak is right. Update() is called every frame, and not every second. That way, time reaches 360 very fast. In order to get the elapsed time since last call to Update, use Time.deltaTime. Which basically means when you do transform.Rotate(Time.deltaTime * speed, 0, 0);, it'll rotate according to your speed. So use a speed measure rather than a time measure.

the rotation starts slowly then increses its speed until (every 2 rounds) it returns to 0.

This is expected behaviour. Like I said, you used time instead of speed. You increase the speed (named: time) every 0.2 seconds, thus increasing the rotation speed.

when i start the game, the object don't rotate

I am unsure why this happens but when you wait long enough, you'll see the rotation occuring anyway. It might be happening but very slowly.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top