So I'm making pong, and I'm trying to get it so that if the ball get's destroyed, there's like a half second before a new one gets instantiated so that the player can go from the bottom of the field to the middle.
here's how I'm destroying:
//When this object enters a hitbox of object 'Col' enter this function
//If this object goes into either goal, destroy this object and increase the score for the opposing player
function OnTriggerEnter2D (col : Collider2D) {
if(col.gameObject.name == "GoalRight") {
Destroy (gameObject);
gameMGMT.GetComponent(GameControlScript).LeftScore();
}
if(col.gameObject.name == "GoalLeft") {
Destroy (gameObject);
gameMGMT.GetComponent(GameControlScript).RightScore();
}
}
and this is how I'm instantiating
function Update () {
if(GameObject.Find("Ball(Clone)") == null)
{
Instantiate(myBall, Vector3(0,0,0), Quaternion.identity);
}
Now you can't yield WaitForSeconds in an update, as it doesn't allow Coroutines (don't understand what that means). So I instead made a seperate function where it could yield and then instantiate. However when I tried that all that happened was it spawned a BUNCH of balls, like a stream that couldn't be handled.
So does anyone have a way of handling this so that the game waits just half a second or so, before instantiating? and when that does happen, obviously only 1 ball is created.
Cheers
↧