I want to count cubes when I collide with them and destroy them. I want an if statement saying if there’s 5 cubes destroyed then it will do something. I just don’t know how to go about doing this though.
public int cubesHit;
public int cubeThreshold = 5;
void OnCollisionEnter(Collision collision)
{
if (collision.collider.gameObject.tag == “SomeCubeTag”)
{
Destroy(collision.collider.gameObject);
cubesHit++;
CheckForCubesHit();
}
}
public void CheckForCubesHit()
{
if (cubesHit >= cubesThreshold)
{
//Do something;
}
}