- Home /
Combining Triggers
I have three objects, two are Triggers, and one is a regular Collider with a script.
Is there a way to avoid needing 2 more scripts just for OnTriggerStay? In other words is there a way to call OnTriggerStay for two seperate triggers in a single script?
Answer by HailTheGreatWolf · Mar 02, 2013 at 10:22 PM
Not sure if this is right but I'd go about it like this (bare in mind I'm refering to Java, sorry) :
In Unity tag each of the Triggers something different.
On the other objects script (with the Collider) in an Update function write if statements for each.
So :
function OnTriggerEnter(hit : Collider)
{
if(hit.gameObject.tag == trigger1)
{
//desired effect here
}
if(hit.gameObject.tag == trigger2)
{
//desired effect here
}
}
I think this is what you're asking for, if I'm wrong sorry.
I'm not looking to see when the regular collider hits the triggers. I think that is what that script does. What I am looking for is to combine all my triggers and colliders in one script.
For example:
A player has a regular collider, but also a trigger disk circling his body like a hula hoop. If something hits the trigger I want to know, all in a single script. This lets me see if the hula hoop trigger collides with a wall so then I can have the player to stick to that wall.
Your answer
Follow this Question
Related Questions
OnTrigger event when colliders are already touching eachother 1 Answer
Activate Script not Working 6 Answers
animation and sound on collide 1 Answer
Play Sound on trigger 2 Answers
Trigger animation going crazy 3 Answers