- Home /
Using the OnTriggerEnter &comparing tags correctly.
Hey I know this may seem like a simple task but I'm struggling with it (total noob). I need the code to specify which function to call depending on the tag of the object my character hits. So if it hits a bubble, it calls the "HitsABubble" function.. and if it hits a prop, it calls for " HitsAProp" function. At the moment if I hit a prop all is good as it calls the correct function, however when I hit a bubble it calls both functions ! I went into the scripting reference searching for an answer and found the "CompareTag" option but I can't quite get my head around it. Any help would be greatly appreciated ! this is the current code I'm working with:
function OnTriggerEnter(object: Collider){
if(object.tag=="bubble")
HitsABubble();
else if(object.tag=="prop")
HitsAProp();
}
Answer by idbrii · Sep 01, 2014 at 11:05 PM
CompareTag is a function call (like HitsAProp
or OnTriggerEnter
) instead of a property (like tag
).
function OnTriggerEnter(other: Collider) {
if(other.CompareTag("bubble"))
{
HitsABubble();
}
else if(other.CompareTag("prop"))
{
HitsAProp();
}
}
Your answer
Follow this Question
Related Questions
OnTriggerEnterProblem 1 Answer
How to make game like Hoops Stack 1 Answer
On Trigger Enter, Collide with object, specific collision 1 Answer
Trigger Spawning? 1 Answer
Collide detection with tag [JS] 0 Answers