Okay, my problem is following:
I can’t seem to get Unity to execute on a defined time. I’ve used the code below, which is very similar to what found on unity’s scripting documentation. So far it print one time at 0, then just rapidly after 5 seconds has passed. What is the thing I’am missing?
Just to clearify it: I want it to print…wait 5 sec…print…wait 5 sec etc.!
function Update () {
var everySec = 5.0;
var nextPrint = 0.0;
if (Time.time > everySec + nextPrint)
{
nextPrint = Time.time;
print(everySec);
}
}
This is the reference code:
// Instantiates a projectile off every 0.5 seconds,
// if the Fire1 button (default is ctrl) is pressed.
var projectile : GameObject;
var fireRate = 0.5;
private var nextFire = 0.0;
function Update () {
if (Input.GetButton ("Fire1") Time.time > nextFire) {
nextFire = Time.time + fireRate;
var clone = Instantiate (projectile, transform.position, transform.rotation);
}
}