- Home /
OnTriggerEnter CompareTag not Working
I have used the OnCollision functions a lot. And decided to use OnTrigger functions to check if the player is within range. However, I noticed that comparing the tag does not work.
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Player")
{
print ("collision");
targetSpotted = true;
}
}
This is supposed to check if the player collides with it, however it does not. If I do this
void OnTriggerEnter(Collider col)
{
print ("collision");
}
I get the print message in my console when it collides with anything. This is a key function of my game. However, if need be I can use an alternate method (Having an individual invisible object on enemies always looking at the player. If the player gets hit by a raycast from this object, then the enemy is to target the player. But that just seems tedious).
Answer by Levithan6785 · Oct 27, 2015 at 03:18 PM
Instead of using either of the methods stated above, just discovered the Vector3.Distance method.
Your answer
Follow this Question
Related Questions
Enemy wont react to bullets 2 Answers
Don't destroy on collision 2 Answers
The problems of Collider .... 1 Answer
OnTriggerEnter(hit : Collider) and (other : Collider) 2 Answers
OnTriggerEnter - Melee Combat 1 Answer