- Home /
Delete certain gameobject if it enters the area.
Hello. I am using this script to delete gameobjects in an area.
function OnTriggerEnter (other : Collider) { Destroy(other.gameObject); }
How can I delete specific gameobjects and not all of them?
Answer by Piflik · Jan 10, 2013 at 11:47 AM
Use tags to identify what object enters the trigger.
if(other.tag == "example") {
Destroy(other,gameObject);
}
I used a tag now.
if (other.gameObject.tag == "Player") {
function OnTriggerEnter (other : Collider) { Destroy(other.gameObject); } }
It gives me errors though.
Edit: I tried the code you gave me but I get the error: $$anonymous$$ identifier 'other'.
Because you are doing it wrong. You have to do the if statement inside OnTriggerEnter.
This is what i have got so far.
function OnTriggerEnter(other,Collider) { if (other.gameObject.tag =="player");{ Destroy(other.gameObject);
}}
I get one error now, unexpected token: , found ';' (right after (other.gameObject)