x


2 Colliders on 1 gameobject

Hello,

I want to be able to have 2 colliders on a gameobject but both being affected by 2 different actions.

Meaning:

Imagine a circle in the air(with 2 circle colliders on). The first collider will be 5x bigger than the circle, the second collider being 2x bigger than the circle. Now if the player collides with the first circle, it will spawn a 'missile' that will fire at the circle and if that 'missile' collides with the second collider, it will destroy the circle and itself. How can i give a title to the two different colliders for the ability i am trying to do to function properly. Like giving that collider a tag or something.

more ▼

asked May 16 '11 at 11:51 AM

Matthew Dennis gravatar image

Matthew Dennis
53 13 15 22

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

1 answer: sort voted first

I am 99% sure you could do this:

  1. Give your gameObject two empty child GameObjects
  2. Attach a different collider to each child object
  3. Write two scripts with your OnColliderEnter functions for each collider
  4. Attach each script to each child object

So in the end you would have:

-Parent GameObject with:
-Child A with Collider A (large collider) and Script A (missile spawning) attached
-Child B with Collider B (small collider) and Script B (destroy on collision) attached

more ▼

answered May 16 '11 at 12:40 PM

GesterX gravatar image

GesterX
2.1k 13 16 37

thank you, this was easier than the way i was planning on doing it. Only thing is i am working with a few prefabs, would this make a difference to anything?

May 16 '11 at 01:15 PM Matthew Dennis

No worries glad to help. Depending on how you're using the prefabs you may need multiple ones.

May 16 '11 at 06:30 PM GesterX
(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:

x2073
x1682
x58
x22

asked: May 16 '11 at 11:51 AM

Seen: 2077 times

Last Updated: May 16 '11 at 11:51 AM