I’ll explain how it works shortly, you have 20 seconds to destroy all the cubes that displayed on the screen, every cube that destroyed will give you 1 point and than if all cubes destroyed so a new bunch of cubes will appear and you will have more 10-15 sec.
when cube destroyed so its renderer and collision is off. when all cubes on screen destroyed so all of the cubes renderer and collision is set to true.
problem is that when all cubes set to true after destroying them, I CANT USE THE METHOD OnMouseDown again to make its hp lower and destroy them.
if(hp <= 0)
{
cube = false; //set cube to false
hp = 0;
if(cube == false) { // cube is always false
cube = false; // cube was false to begin with
from your logic, each cube has 100hp, each click takes 30hp off. Therefore if cube has been clicked 4x(a.counter = 4), its hp is reset to 1 and its hidden(collider/render off) < player cannot click since render is off.
“Somehow” a.counter gets to 15, and its set back to hp=100,render etc…
if thats the logic you want, you need another object that will announce to all the cube to wake up e.g. GameController. At this point i still dont know who keeps the timer i.e. 20s, 10-15s.
so your game controller starts by finding all the cubes and then on first timer 20s reached, reset all the cubes a.counter to 15 which would in turn reset the cubes and consequently runs another 10-15s.