Hello!
I want to make a simple game. There will be some objects to appear on the screen and a player will have to touch them in the same order how they appeared before. If they will touch wrong(in a different order), then the game will be over. Any ideas? How can I do it?
Thanks a lot!
As you add the items, put them in a List (ordered collection). This way the order of them in the List is the order they need to be touched.
Have an index variable representing the current index in the list you need to touch. It should start at 0 (the first element in the List).
Have some ‘touch’ mechanism on the objects… a Collider configured as Trigger is good. And OnTriggerEnter you check if the entered item is the element at the ‘index’ in the list. If it is, then increment the index to the next. If it’s not, then fail.
I have just 5 objects and they will be appear random, they could be repeated. Also, I want to appear one object per second, doesn’t matter if the previous object isn’t touched already and destroyed.
“As you add the items, put them in a List (ordered collection). This way the order of them in the List is the order they need to be touched.”
Also, I don’t want to make more levels to set a order for each level, I want to spawn those objects randomly in a single scene (endless spawn).
When you randomly generate them… add them to the list.
void GenerateThing()
{
var obj = Instantiate(objPrefab, somePosition, someRotation);
theList.Add(obj);
}
Pretty straight forward.
In the Update loop, you place LordofDuct’s code followed by a 1 second countdown timer, and a variable to decrement until you have created all the objects for that level.
Better, you could use a coroutine that contains the spawning loop with a 1 second WaitForSeconds(n) to do the spawning.