public void UpdateTarget() { GameObject closestPlayer = RangeHelper.GetClosestWithTag(gameObject, Constants.playerTag); if (closestPlayer != null) { hasTarget = true; isTargetInRange = RangeHelper.CheckIfTargetIsInRange(gameObject, closestPlayer, myGun.bulletRange); targetPosition = closestPlayer.transform.position; if (isTargetInRange) { timeBetweenMessagesCounter -= Time.deltaTime; if (timeBetweenMessagesCounter < 0) { ResetMessageTimer(); RandomSendMessage(); } } } else { hasTarget = false; isTargetInRange = false; } }