/// <summary> /// Evaluates the current position of the enemy to decide whether to /// attack or not. /// </summary> void EvaluatePlayerPosition() { if (!player.healthProperties.alive) { return; } if (ProgressionManager.Instance.gameOver) { return; } Vector2 difference = player.transform.position - transform.position; var playerScreenPos = Camera.main.WorldToScreenPoint( player.transform.position ); moveable.TurnToScreenPoint(playerScreenPos); if (weaponAttacker == null) { weaponAttacker = GetComponentInChildren <IWeaponAttacker>(); } try { if (weaponAttacker.InRange(difference.magnitude)) { combat.Attack(); } else { moveable.Move(difference); } } catch (System.NullReferenceException) { Debug.LogWarning("It did it again"); moveable.Move(difference); } }
/// <summary> /// Rotates the object based on mouse pointer location. /// </summary> void ProcessRotationInput() { moveable.TurnToScreenPoint(Input.mousePosition); }