- Home /
Swapping object position?
Hello. I want to have a system so that when a power ups appears on screen, if the player does not grab it, I want it to decay into a collectable of a lower value (ex: An extra life decays into an extra bomb). How can I, after a certain amount of time, swap out an objects position with another prefab? Thanks.
Answer by Jesse Anders · Dec 11, 2010 at 06:09 AM
The meaning of the phrase 'swap out an object's position' isn't really clear, but I gather what you're wanting is to have one object turn into another object after a specified time interval has elapsed.
If that's the case, first you need a way to keep track of time and execute an appropriate action when a specified period of time has elapsed. Common solutions to this problem include keeping track of time manually using (e.g.) Time.deltaTime, using a coroutine, or using Invoke().
When it comes time to swap out the powerup, use Instantiate() to create a new object at the same position, and then use the Destroy() function to destroy the game object representing the currently active powerup. This will effectively remove the old powerup and replace it with a new one.
Your answer
![](https://koobas.hobune.stream/wayback/20220613090606im_/https://answers.unity.com/themes/thub/images/avi.jpg)