- Home /
OnTriggerEnter just if name of trigger is something
Hi, I have 2 things which I want to work with OnTriggerEnter. Turbo and Portal. How can I check the name of Object with Trigger?
function OnTriggerEnter(other : Collider){
//just do this if object name/tag is Turbo
other.rigidbody2D.AddForce(Aim.position*10);
}
Answer by tanoshimi · Dec 28, 2014 at 09:59 AM
if(other.gameObject.name == "Turbo") { ... }
else if(other.gameObject.name == " Portal") { ... }
I dont need name of object that Enters. I need name of Object which have a trigger.
Even easier then:
if(gameObject.name == "Turbo") { ... }
else if(gameObject.name == " Portal") { ... }
I have little pixels which are flying everywhere and I want to know what they have entered.
I dont know if I spelled word Entered correctly.
Ohhh that works thanks.
btw if want to know what did u helped with https://play.google.com/store/apps/details?id=com.nexgea.dustexperiment
Answer by unigeek · Dec 28, 2014 at 10:55 AM
Looks weird to me. If your object is always "Turbo" or always "Portal" it will be easier to have specific behavioral scripts attached to them and don't check the name at all. Furthermore, in case the object's name changes you will have to bring dependent scripts back to consistent state - better use a flag or other property.