x


if hit something

hi,

does anybody of you know how I can do that if a gameobject (with a collider) hits an object it does something like this:

 if(Robot.hit(this)){ blabla(); }

more ▼

asked Jun 19 '11 at 11:12 AM

bubblegumsoldier gravatar image

bubblegumsoldier
51 15 25 34

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

3 answers: sort voted first

Using Javascript you would do something like this:

function OnTriggerEnter(otherObject: Collider){

if(otherObject.gameObject.tag == "Robot"){

blabla();

}

You would also have to create a tag and name it Robot, then select that tag on the object you want to collide. Also you might have to set one of the 2 objects that are colliding to be the trigger.

more ▼

answered Jun 19 '11 at 11:36 AM

Arachnos gravatar image

Arachnos
31 8 10 11

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

This is easy, for more information visit this link: http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html

Any questions, ask ;D Hope this help

more ▼

answered Jun 19 '11 at 11:45 AM

Unamine gravatar image

Unamine
362 14 17 27

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

Collider enter:

function OnColliderEnter (hit : Collision) { Destroy(hit.gameObject); }

Trigger enter:

function OnTriggerEnter (hit : Collider) { Destroy(hit.gameObject); }

more ▼

answered Jun 19 '11 at 11:54 AM

realm_1 gravatar image

realm_1
16 2 2 4

thx for all these fast information...

Jun 19 '11 at 12:19 PM bubblegumsoldier
(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:

x1692
x193
x146
x8

asked: Jun 19 '11 at 11:12 AM

Seen: 1204 times

Last Updated: Jun 19 '11 at 12:19 PM