x


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.

more ▼

asked Dec 11 '10 at 05:52 AM

Tyler 2 gravatar image

Tyler 2
1.1k 211 246 264

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Dec 11 '10 at 06:09 AM

Jesse Anders gravatar image

Jesse Anders
7.3k 7 17 48

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1094
x885
x51

asked: Dec 11 '10 at 05:52 AM

Seen: 1135 times

Last Updated: Dec 11 '10 at 05:52 AM