if(Vector3.Distance(transform.position, Player.PlayerPosition) <= AggroRange && AggroTrigger == true){
transform.LookAt(Player.PlayerPosition);
if( Vector3.Distance(transform.position, Player.PlayerPosition) > MinRange ){
transform.Translate (Vector3.forward * EnemySpeed * Time.deltaTime);
}
if(CanAttack == true && AggroTrigger==true)
{
AggroTimer = 20;
Player.PlayerHealth -= 20;
CanAttack = false;
AttackSpeed = 0;
}
}
So I am obviously telling Unity: if the distance betweeen the player and enemy is smaller than or equals to 50, and AggroTrigger is true, execute the code, the problem is even when AggroTrigger is false it executes it, I have no clue where I might be wrong since if statements should be the simplest thing, Unity is just not listening to me, maybe it’s a bug, maybe I’m stupid, but I just want to fix this annoying problem.
AggroTrigger becomes true when AggroTimer is between 1 and 20, false if it’s 0 or above 20.