Beispiel #1
0
        public void OnAttack(GameObject attacker, Attack attack)
        {
            if (_isInvincible || IsInvicibleMovement())
            {
                //Do something if invincible
            }
            else
            {
                //Update health
                UpdateCurrentHealth(_currentHealth - attack.Damage);

                //Apply the effect of the attack
                if (attack.Effect != null && _stats != null)
                {
                    attack.Effect.Invoke(_stats);
                }


                if (attacker != null)
                {
                    Debug.Log(gameObject.name + " got attacked by " + attacker.name + " and did " + attack.Damage + " damages");
                }

                //Play sound, vfx and animation
                if (gameObject.tag.Equals("Player"))
                {
                    _sfx.LowHealth();
                }

                CharacterAttackManager atkMgr = attacker.GetComponent <CharacterAttackManager>();
                if (!attacker.tag.Equals("Creature") && !attacker.tag.Equals("Traps"))
                {
                    if (atkMgr)
                    {
                        _vfx.TouchImpact(transform.position, atkMgr.GetVfxTouchImpact());
                        _sfx.EnemyDamageSFX();

                        //Become invincible
                        StartInvincibility(_invincibleTime);
                    }
                }

                if (!attacker.tag.Equals("Creature") && gameObject.tag.Equals("Player"))
                {
                    // Player take damage
                    _sfx.PlayerDamageSFX();
                    _vfx.FlashScreenDmgPlayer();
                    ControllerVibration.Instance.StartVibration(_takeDamageVibration);
                    _invAnim.LaunchAnimation();

                    //Become invincible
                    StartInvincibility(_invincibleTime);
                }

                //Do something if critical
            }
        }