I’m building a game in which the player collect cubes and i have an exit that is blocked by a wall. How do i make the wall move after i’ve collected all cubes?
You could;
- Create an int to use as a counter in a manager class
- When the cubes spawn, have them add 1 to that int.
- When they are collected and get destroyed, have the cubes deduct one from that int.
- When the int gets to 0, remove the wall.
I assume you have a class which creates and places the collectables. So you could just add the code below to that class and give the cubes a reference to said class when they are spawned.
private int _cubeCounter;
public void OnCubeCollected()
{
_cubeCounter--;
if (_cubeCounter <= 0)
{
//Code to move wall
}
}
i can count the cubes i just can’t move the wall