void UpdateHealth(float f, GameplayStatics.DamageType type)
 {
     if (m_HealthSlider && m_StatusComponent)
     {
         m_HealthSlider.fillAmount = m_StatusComponent.GetCurrentHealth() / m_StatusComponent.GetMaxHealth();
     }
 }
    public void TakeDamage(float amount, GameplayStatics.DamageType type = GameplayStatics.DamageType.Normal)
    {
        if (!m_IsInvincible)           // if the target can take damage
        {
            m_CurrentHealth -= amount; // reduce your health
            m_CurrentHealth  = Mathf.Clamp(m_CurrentHealth, 0.0f, m_MaxHealth);
            if (m_CurrentHealth <= 0.0f && m_OnDeath != null)
            {
                m_OnDeath.Invoke();                                               //if the actor is dead, call death event
            }
            if (m_OnTakeDamage != null)
            {
                m_OnTakeDamage.Invoke(amount, type);                         // call take damage event
            }
            var col = gameObject.GetComponent <Collider2D>();
            var pos = col.bounds.center + col.bounds.extents;

            // pos = transform.position;
            if (m_DamagePopupOverride == GameplayStatics.DamageType.Null)
            {
                GameplayStatics.SpawnDmgPopup(pos + new Vector3(0, 0, -5), amount, type);
            }
            else
            {
                GameplayStatics.SpawnDmgPopup(pos + new Vector3(0, 0, -5), amount, m_DamagePopupOverride);
            }

            StartCoroutine(FlashSprite(m_HitFlashDuration)); // flash the sprite material if it can
            if (m_CanUseIFrames)                             // if the actor can use i frames
            {
                m_IsInvincible = true;                       // make it invincible for the iframe duration
                StartCoroutine(StartIFrame(m_IFrameTime));
            }
        }
    }
    public static bool DamageOnCollide(
        GameObject target,
        SpellPrefabManager src,
        float damage,
        List <string> ignore            = null,
        GameplayStatics.DamageType type = GameplayStatics.DamageType.Normal)
    {
        if (ignore != null)
        {
            if (GameplayStatics.ObjHasTag(target, ignore))
            {
                return(false);
            }
        }

        if (src)
        {
            if (target != src.GetOwner() && !SpellVerifySameOwnership(target, src.GetOwner()))
            {
                GameplayStatics.ApplyDamage(target, damage, type);
                return(true);
            }
        }
        return(false);
    }
 public void Heal(float amount, GameplayStatics.DamageType type = GameplayStatics.DamageType.Heal)
 {
     m_CurrentHealth += amount;
     m_CurrentHealth  = Mathf.Clamp(m_CurrentHealth, 0.0f, m_MaxHealth);
     GameplayStatics.SpawnDmgPopup(transform.position, amount, type, false);
     if (m_OnReceiveHeal != null)
     {
         m_OnReceiveHeal.Invoke(amount, type);
     }
 }
 public void MakePlayerInvulnerable(float useless, GameplayStatics.DamageType type)
 {
     StartCoroutine(GameplayStatics.Delay(m_StatusComponent.m_IFrameTime, () => this.gameObject.layer = LayerMask.NameToLayer("PlayerInvulnerable"), () => this.gameObject.layer = LayerMask.NameToLayer("Player")));
 }
Exemple #6
0
 private void HitObject(float damage, GameplayStatics.DamageType type)
 {
     ObjectAnimator.SetTrigger("Hit");
 }