Im making a little 2D Game in Unity and im new in Programming.
I want to make a Check List with 5 GameOBjects.
The Player has to destroy this 5 GameObjects (Cubes) in a specific order. (first cube1, second cube2,…).
(i already have a destroy script)
I know how to make Checklist, but how can i write a script, that checks if Cube1 was destroyed as the first one, cube2 as the second one an so on, otherwise a Game Over will appear.
Not sure if I understood your concern correctly. What I guess is that the user will destroy the cubes at his will and you want to check if the destroyed cube was the next to be destroyed object or not. I am a beginner in programming as well, so my solution would not be the most efficient.If you will have only a few objects, like you say, then you could use different Tags for each one. For example Cube1, Cube2, etc. Next, I don’t know your destruction method, but somehow you interact with the object to be destroyed. At this point check if the cube’s tag is the correct one. In pseudo code:
var counter : int = 1;
var cubeToBeDestroyed : String = “Cube” + counter.ToString();
var correctCube : boolean = true;
function Update() {
if a cube is GOING TO be destroyed {
if (cube.tag == cubeToBeDestroyed) {
correctCube = true;
} else {
correctCube = false;
}
counter++;
cubeToBeDestroyed = “Cube” + counter.ToString();
}
if (!correctCube) {
GameOver();
}
}