- Home /
How to check trigger events through the same script?
Hello!!
Well I was wonder whether or not it is possible to check more than one trigger event in one script.
I know how to check one trigger event in a script, but what if I want to check more than one? Do I have to add a script to every object that check its own trigger, or I can make it happen with a faster way?
Please answer in Javascript, but if you want answer in C# ! :)
If I understand correctly, no, you cannot receive object B's trigger events in object A's script.
Answer by VOTRUBEC · Feb 05, 2015 at 12:49 AM
This might be what you're looking for:
void OnTriggerEnter2D ( Collider2D other )
{
switch ( other.gameObject.tag )
{
case "ObjectATag":
DoSomething ( );
break;
case "ObjectBTag":
DoSomethingElse ( );
break;
}
}
If I understand correctly, you mean to check from this script the object tags that enter the trigger, right? Well if yes I dont mean that! I mean to check from one script triggers from other objects!
Your answer