- Home /
Collecting game objects in specific order
I have some objects that need to be collected. Each object has a number assigned (1,2,3,etc).
How would I go about making sure these objects are collected in the order they are numbered?
Answer by HarshadK · Jul 08, 2014 at 11:23 AM
The logic for such a situation will go as below:
Set an integer variable for last collected item like lastItemCollected.
Then when user tries to collect an item check if that item is lastItemCollected+1.
If yes then add that item to your collected items list and update the value of lastItemCollected by one.
If not then do not allow to collect that object.
You need to tweak this logic to suit your needs. :-)
Thanks for that, it worked well. However, quick question on topic. What if I need to get the next game object after picking one up?
Not quite sure as to what you are asking. Can you elaborate.
Its basically for an arrow system which points to the next game object. So when you collect the first one I need to get the position of the second one so the arrow can point to it. Just not sure how to get the next item.
You can find the next game object of current object by using the GameObject.Find() considering the name of the game object has the number which you need to collect. Then get the position of that game object using gameObject.transform.position.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
C# Check If Gameobject is within Collider 1 Answer
C# Preserving GameObjects' Previous Meshes 1 Answer
Player instantiates Backwords 0 Answers