/// <summary>
    /// Performs a melee attack.
    /// </summary>
    /// <param name="obj">The GameObject that wants to execute this action.</param>
    /// <returns>Returns true if this action is executed successfully, false otherwise.</returns>
    public override bool Execute(GameObject obj)
    {
        base.Execute(obj);
        GameObject player = GameObject.FindGameObjectWithTag("Player");

        if (player == null)
        {
            return(false);
        }

        EntityHealthManager healthManager = player.GetComponent <EntityHealthManager>();

        if (healthManager == null)
        {
            return(false);
        }

        healthManager.InflictDamage(attackDamage);
        timer.Reset();
        return(true);
    }
Exemple #2
0
    /// <summary>
    /// Attack the target
    /// </summary>
    /// <param name="_player">The Player's GameObject</param>
    /// <returns>true if the attack succeeded (e.g. we didn't run out of arrows)</returns>
    public override bool Execute(GameObject _player)
    {
        base.Execute(_player);

        Player player;
        float  dmg;

        player = (Player)_player.GetComponent <EntitySpriteManager>().entity;
        dmg    = weapon == null ? player.FisticuffDamage : weapon.Damage;

        GameObject attackAnimationObj = player.AttackAnimationObject;

        //attackAnim.CreateAnimation(player, attackAnimationObj, weapon, targetTransform, animationSpeed);
        attackAnimationObj.GetComponent <AttackAnimation>().CreateAnimation(player, attackAnimationObj, this.weapon, this.targetTransform, this.animationSpeed);
        attackAnimationObj.GetComponent <Animation>().Play("attack");

        targetHM.InflictDamage(dmg);

        //Debug.Log(tmpSprite.GetInstanceID());

        return(true);
    }