- Home /
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(); }
Answer by Arachnos · Jun 19, 2011 at 11:36 AM
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.
Answer by Unamine · Jun 19, 2011 at 11:45 AM
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
Answer by realm_1 · Jun 19, 2011 at 11:54 AM
Collider enter:
function OnColliderEnter (hit : Collision) { Destroy(hit.gameObject); }
Trigger enter:
function OnTriggerEnter (hit : Collider) { Destroy(hit.gameObject); }