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).
Instead of using either of the methods stated above, just discovered the Vector3.Distance method.