I have a specific problem with my trigger
I am sort of new with Unity, and I am making my first game currently. Sorry if I seem like a noob. I have been using triggers, but I cant seem to get this specific part to work.
void OnTriggerStay(Collider col)
{
if (col.gameObject.tag == "Enemy" || col.gameObject.tag == "FastEnemy" || col.gameObject.tag == "TankEnemy")
{
EnemyCoords = col.gameObject.transform.position;
transform.parent.GetComponentInChildren<MGTURRET>().EnemyCoords = EnemyCoords;
Debug.Log(col.gameObject.tag);
}
else
{
Debug.Log("Not Colliding");
transform.parent.GetComponentInChildren<MGTURRET>().Firing = false;
Shooting = false;
}
}
This is part of my code for a turret that I have made. It locks on to the nearest enemy, and shoots at it. The turret starts shooting when an object with one of those tags enters the trigger, but I want it to stop shooting when there is no object with those tags colliding with the trigger. It is weird because when I test the game out, the debug log always says "Not Colliding", even though it is colliding with an enemy, and the debug log also says that it is colliding with enemies. Isn't anything under the 'else' supposed to run if none of the conditions are met above? It is still running everything below the 'else', even though the conditions above are met. So it is basically acting like it is colliding with an enemy and not colliding with an enemy at the same time. I am stumped.
Your answer
Follow this Question
Related Questions
2D Power up script not working 0 Answers
Certain commands are missing? 1 Answer
Unity 5.3.5f1 personal + Visual Code 1.3.1 Code Suggestion 1 Answer
My animation is working but the character won't move. 2 Answers
Visual studio not showing errors at all,Visual Studio not showing errors. I'm not sure what to do. 0 Answers