Example #1
0
 void Start()
 {
     player         = ReferenceManager.Instance.player.GetComponent <Character>();
     character      = GetComponent <Character>();
     combat         = GetComponent <CharacterCombat>();
     moveable       = GetComponent <IMoveable>();
     weaponAttacker = GetComponentInChildren <IWeaponAttacker>();
 }
    void Start()
    {
        animator       = GetComponent <Animator>();
        weaponAttacker = GetComponentInChildren <IWeaponAttacker>();
        sr             = GetComponent <SpriteRenderer>();

        hitFlashShader = Shader.Find("GUI/Text Shader");
        defaultShader  = sr.material.shader;
        defaultColor   = sr.color;
    }
Example #3
0
    void FixedUpdate()
    {
        if (!character.healthProperties.alive)
        {
            return;
        }

        if (!weaponAttackerHotloadAttempted && weaponAttacker == null)
        {
            weaponAttacker = GetComponentInChildren <IWeaponAttacker>();
            weaponAttackerHotloadAttempted = true;
        }

        EvaluatePlayerPosition();
    }
Example #4
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);
        }
    }