- Home /
How can i make different OnTriggerEnter actions into one Script?
Hello Unity-Community, my problem is, that i have 2 different pickup objects(one with sphere collider, the other one with box collider) and i dont know how to do different actions with these colliders, when my player object enters their Trigger. Because if i add another collider onto my OnTriggerEnter function, it doesnt work anymore.
In my case the actions are, that one objects counts 1, the other 3.
It would be awsome if some1 can help me :)
Answer by Digital-Phantom · Mar 24, 2015 at 12:22 PM
Put an OnTriggerEnter method on the pickup items instead.
or
Use tags to differentiate between each item. Something like -
void OnTriggerEnter (Collider other)
{
if (other.tag == "Bolt")
{
Destroy(other.gameObject);
Instantiate(asteroidExplosion, transform.position, transform.rotation);
Destroy(gameObject);
}
if (other.tag == "Boundary")
{
Destroy(gameObject);
}
Answer by Mehul-Rughani · Mar 24, 2015 at 11:54 AM
You can not add multiple parameter to OnTriggerEnter() method.. There will be only one parameter.. http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html