Exemplo n.º 1
0
    /*====================FORMAT IN PROGRESS====================*/
    public override void TakeDamage(float amount, Vector2 knockBackForce, bool flinch, HealthScript attacker = null, float freezeDelay = 0.0f, Collider2D gotHitCollider = null)
    {
        currentHealth -= amount;
        enemyAI.AddForce(knockBackForce.x, knockBackForce.y);

        if (flinch)
        {
            enemyAI.ChangeState(AIStates.FLINCHED);
        }

        if (gotHitCollider)
        {                                                                                                                                                         // Pass attacker (their health scripts) and 'this object's collider that was hit' as argument for hiteffect instantiation.
            Vector3    hitPos         = gotHitCollider.bounds.ClosestPoint(new Vector3(attacker.transform.position.x, attacker.transform.position.y + 0.86f, 0)); // 0.86f is the shoulder height of yasushi.
            GameObject hitEffectInst  = Instantiate(hitEffect, hitPos, attacker.transform.rotation);
            Vector3    hitEffectScale = hitEffectInst.transform.localScale;
            hitEffectScale.x *= Mathf.Sign(attacker.transform.position.x - gotHitCollider.transform.position.x);
            hitEffectInst.transform.localScale = hitEffectScale;
        }

        if (attacker != null && freezeDelay > 0)
        {
            attacker.FreezeFrames(freezeDelay);
            FreezeFrames(freezeDelay);
        }

        if (currentHealth <= 0 && canDie)
        {
            vulnerable = false;
            canConsume = false;
            consumeIndicator.gameObject.SetActive(false); // Turn off the consumeIndicator why dying anim is playing so that it won't confuse the player.
            enemyAI.ChangeState(AIStates.DEAD);           // Dead state plays death animation and call DestroyEnemy() at the end of its anim.
        }
        else if (currentHealth <= (MaxHealth * 0.2))      // When health fell under 20%, enemies became consumable.
        {
            enemyAI.ChangeState(AIStates.CONSUMABLE);
            canConsume = true;
            consumeIndicator.gameObject.SetActive(true);
            if (this.name == "Tempura1" || this.name == "MakiRoll1" || this.name == "Chuka1")
            {
                vulnerable  = false;
                this.canDie = false;
            }
        }
    }