When teaching young students it can be difficult to explain the following code and I’m wondering if there may be an easier way to write this - perhaps using wait or waitforseconds which would remove the need for the additional variables and Time.time business:
var ball : GameObject;
var nextspawn : float=0.0;
var spawninterval : float=0.5;
function Update () {
if (Time.time>nextspawn){
nextspawn=Time.time+spawninterval;
Instantiate(ball,transform.position,transform.rotation);
}
}
Any thoughts on ways to simplify the above (for teaching purposes) would be appreciated.
function Update () {
if ( currentTime > timeOfNextSpawn){
// Update time of next spawn
timeOfNextSpawn = currentTime + spawnInterval;
// Create a new ball
CreateNewBall();
}
}