x


switch object when collided with?

i want to switch object 1 to object 2 when collided with my object. how can i do that? object 1 being a gameObject that has 1 cube and object 2 being a gameObject that has 6 spheres in for an example. first 20 CORRECT AND HELPFUL ANSWER ILL PAY THEM $276-$2,000

more ▼

asked Jul 05 '11 at 03:32 PM

smasgames gravatar image

smasgames
34 25 29 32

I personally wouldn't post a helpful comment for a penny less than $277. ;)

Jul 05 '11 at 10:33 PM Ipsquiggle
(comments are locked)
10|3000 characters needed characters left

2 answers: sort oldest

Consider the basic steps that are required here:

  1. Detect your collision
  2. destroy object1
  3. instantiate object2

Short of writing your script for you (which I try to avoid), that's your answer. Please remember to search through old answers before posting; this kind of thing get asked often and there are plenty of solutions there to look through.

more ▼

answered Jul 05 '11 at 03:40 PM

Chris D gravatar image

Chris D
2.5k 5 7 25

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

make a gameobject variable and assign your second object into it and add the following script to your first object. it instantiates the second object when the first object collides with something.

var object2 : GameObject;

function OnCollisionEnter (col : Collision) {
     Instantiate(object2, transform.position, transform.rotation);
     Destroy(gameObject);

}
more ▼

answered Jul 05 '11 at 03:42 PM

Taran0 gravatar image

Taran0
49 3 4 11

@Taran0 don't forget to format the code you post : )

Jul 05 '11 at 04:20 PM Chris D
(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:

x2499
x379
x237
x142
x13

asked: Jul 05 '11 at 03:32 PM

Seen: 812 times

Last Updated: Jul 15 '11 at 09:06 PM