Exemplo n.º 1
0
    /// <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);
        }
    }
Exemplo n.º 2
0
 /// <summary>
 /// Rotates the object based on mouse pointer location.
 /// </summary>
 void ProcessRotationInput()
 {
     moveable.TurnToScreenPoint(Input.mousePosition);
 }