- Home /
GameObject automatically moves up when upgrade is purchased.
Hello, I have a list of 4 gameobjects. They are all upgrades, so for when I click the first one, the gameobject is destroyed, great, but I want the rest of the three upgrades to automatically move up after I have bought an upgrade. Kind of like the upgrade system in Adventure Capitalists. Any ideas? Thanks, nightdev.
Still need an answer as soon as possible. Please and thanks.
Answer by Whitecold · Sep 24, 2017 at 08:10 AM
If you are using some layout group, it should automatically readjust if you delete some items
No, I am talking about while in game. The object would disappear and the rest would move up automatically let's say when that object is pressed. If that makes sense...
Answer by lilscarecrow · Oct 09, 2017 at 04:17 PM
You could use a queue to achieve this. Each index in the queue could tell what the objects position should be and you could dequeue an entry when its clicked.
Would there be a specific system used to make this queue? Like a list? I understand what you mean but doesn't make sense on how I would achieve this.
There's a built in queue you could use that basically serves as a list with the options to enqueue/dequeue/peek/etc. So you could make a queue with the type of your gameObjects and insert them in the order you want with the positions desired at each index. So you could iterate the queue and set the gameObject at each index to achieve this (maybe only update each objects position when you enqueue/dequeue). So the way I would approach would be like this: 1. At the start build your queue up (if this information is known at startup) 2. Have a function that will update the position of the gameObjects within the queue at each index 3. Have a function that gets called when you want to remove the item from the queue and dequeue it (ex. click on the item -> call the dequeue function) 4. When you dequeue, make sure to call your function to update all positions again
One problem with this approach is if you want to remove items that are NOT next in line, like the 3rd index. In that case you could do something similar but would want to use a linked list or something else rather than a queue.
where would this built in queue be located?