I’m making a brick breaker and there’s a ball which is out of view and when it instantiates itself whenever I collect a power up so that I have many balls. I want to check if all instantiated objects have been deleted so that its game over. I don’t want the code to be really complicated and stuff
make new variable:
public int ballsCount = 1; // because one of the ball is already on the scene.
then in your code when you Instantiate
the balls put:
ballsCount++;
in your code where you are destroying the ball put:
ballsCount--;
and then in your code where you are destroying the ball put: (you can put this in the Update
but it is not good way because it will be checking ballsCount every frame - if the game is simple should be okay)
if (ballsCount <= 0)
{
// gameOver logic here
}
Something like that.
Thank you so much. My code works now… I really appreciate you