Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Trying WaitForSeconds before Instantiating

$
0
0
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

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>