private bool UpdateHealth(float delta)
        {
            if (Health > 0f)
            {
                var oldHealth = Health;
                var newHealth = Health + delta;

                if (Splits > 1 && Math.Ceiling(oldHealth / _splitHealth) > Math.Ceiling(newHealth / _splitHealth))
                {
                    var enemy = Instantiate(gameObject, transform.position, Quaternion.identity, transform.parent);
                    enemy.transform.localScale /= 1.5f;
                    enemy.GetComponentInChildren <Move>().CurrWaypoint = GetComponentInChildren <Move>().CurrWaypoint;

                    var enemyBase = enemy.GetComponent <EnemyBase>();
                    enemyBase.MaxHealth.Base /= Splits * 2;
                    enemyBase.Speed          *= 1.5f;
                    enemyBase.Splits         /= 2;
                    enemyBase.Level           = _level;

                    GameState.Instance.RegisterEnemy(enemy);
                }

                Health = newHealth;
                _healthBar.localScale = new Vector2(Math.Max(Health / MaxHealth.Value, 0f), 1f);
                if (Health <= 0f)
                {
                    OnDie?.Invoke(this, gameObject);
                    _animator.SetBool("Dead", true);
                    return(true);
                }
            }
            return(false);
        }
    public void ReceiveAnAttack(int damage)
    {
        if (IsDead)
        {
            return;
        }

        _currentHealthSO.InflictDamage(damage);

        if (_updateHealthUI != null)
        {
            _updateHealthUI.RaiseEvent();
        }

        GetHit = true;

        if (_currentHealthSO.CurrentHealth <= 0)
        {
            IsDead = true;

            if (OnDie != null)
            {
                OnDie.Invoke();
            }

            if (_deathEvent != null)
            {
                _deathEvent.RaiseEvent();
            }

            _currentHealthSO.SetCurrentHealth(_healthConfigSO.InitialHealth);
        }
    }
    public void TakeDamage(float amount)
    {
        if (IsDead)
        {
            return;
        }

        if (amount < 0)
        {
            durability = 0;
        }
        else
        {
            durability = Mathf.Clamp(durability - amount, 0, maxDurability);
        }

        if (durability <= 0)
        {
            IsDead = true;
            OnDie?.Invoke();
            if (destroyGameObjectOnDeath)
            {
                Destroy(gameObject);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        //Debug.LogWarning("UPDATE : " +  currState);
        if (GameState.PAUSE == currState || GameState.GAME_OVER == currState || GameState.DYING == currState)
        {
            return;
        }

//        if (player?.position.z > zMaxDistance)
//        {
//            OnPlayerReachLimit?.Invoke(zMaxDistance);
//        }

        if (player == null)
        {
            //game conditions
            if (GameFlow.LifeCount > 0)
            {
                currState = GameState.DYING;
                GameFlow.LifeCount--;
                OnPlayerReachLimit?.Invoke(zMaxDistance);
                OnDie?.Invoke();
                Debug.LogWarning("DYING : " + GameFlow.LifeCount);
            }
            else
            {
                currState = GameState.GAME_OVER;
                OnGameOver?.Invoke();
            }
        }
    }
        public int AddHealth(int value)
        {
            if (IsDead)
            {
                return(0);
            }

            Health += value;
            if (Health >= c_MaxHealth)
            {
                Health = c_MaxHealth;
            }

            if (Health <= 0)
            {
                Health = 0;
                IsDead = true;
            }

            OnHealthChanged.Invoke(Health);

            if (IsDead)
            {
                Image.Load(m_DeathBitmap);
                OnDie.Invoke();
            }

            return(Health);
        }
Exemple #6
0
        private void EndGame()
        {
            if (GameOver || processColision)
            {
                return;
            }

            Pacman.Stop();
            Ghosts.ForEach(x => x.Stop());

            if (LifeCount > 0)
            {
                LifeCount--;
                WaitAndCall(((int)TIME_TO_RESET * 1000), InitiateGame);
            }
            else
            {
                OnGameOver?.Invoke();
                GameOver = true;
                UnityEngine.Debug.LogWarning("GAME OVER");
            }

            OnDie?.Invoke();

            processColision = true;
        }
Exemple #7
0
 public void Kill()
 {
     motor.animator.SetBool("Character/Dead", true);
     motor.animator.CrossFadeInFixedTime("Die", 0.2f);
     Destroy(GetComponent <Target>());
     OnDie?.Invoke();
 }
Exemple #8
0
 private void Die()
 {
     OnDie?.Invoke(this);
     Gamemanager.instance.OnEnemyDieHandler(pointsToGive, extraTime);
     Gamemanager.instance.enemiesController.ItemToDrop(this.transform.position, chanceToSpawnItem);
     Destroy(this.gameObject);
 }
    public void TakeDamage(float amount)
    {
        if (amount < 0)
        {
            throw new System.Exception("You can't deal a negative damage value to the character health");
        }

        if (OnReceiveDamage != null)
        {
            OnReceiveDamage.Invoke(amount);
        }

        _health -= amount;
        _health  = Mathf.Clamp(_health, 0, maxHealth);

        if (OnHealthChange != null)
        {
            OnHealthChange.Invoke(_health);
        }

        if (_health == 0 && OnDie != null)
        {
            OnDie.Invoke();
        }
    }
Exemple #10
0
 private void Update()
 {
     if (transform.position.sqrMagnitude >= 20000)
     {
         OnDie?.Invoke(this);
         Destroy(gameObject);
     }
 }
 void EndDie()
 {
     Animator.ResetTrigger(DeathHash);
     Animator.SetTrigger(DeadHash);
     Collider.enabled = false;
     UpdateParams();
     OnDie?.Invoke();
 }
Exemple #12
0
    private IEnumerator Die()
    {
        yield return(new WaitForNote(Note.Quarter, 3));

        bloodSpurtVfx.Stop();
        bloodSpurtVfx.Destroy();
        OnDie?.Invoke(this);
    }
Exemple #13
0
        private IEnumerator WaitForAnimationToEnd()
        {
            OnDie?.Invoke();
            RigidBody2D.velocity = Vector2.zero;
            yield return(new WaitForSeconds(1.67f));

            OnResetLevel?.Invoke();
            ResetPlayer();
        }
Exemple #14
0
 public void Die()
 {
     if (!IsDead)
     {
         IsDead = true;
         arena.Kill(this);
         OnDie.Invoke();
     }
 }
    private void Die()
    {
        OnDie?.Invoke();

        birdMovement.ResetVelocity();
        visualTransform.localEulerAngles = new Vector3(
            visualTransform.localEulerAngles.x,
            visualTransform.localEulerAngles.y,
            -90);
    }
    public virtual void Die()
    {
        //Debug.Log("DIE");
        IsDied = true;

        if (onDieCallback != null)
        {
            onDieCallback.Invoke();
        }
    }
 private void OnDisable()
 {
     if (!ZombiesManager.Singleton.gameOver)
     {
         if (OnDie != null)
         {
             OnDie.Invoke();
         }
     }
 }
Exemple #18
0
        private void Die()
        {
            OnDie?.Invoke();

            _metronome.PlayEvent(5);
            Animator.SetTrigger("Dead");
            _playing = false;
            _playOk  = false;

            Invoke(nameof(EndGame), 1);
        }
        public void Damage(int value)
        {
            m_LifeCount--;

            if (m_LifeCount <= 0)
            {
                OnDie?.Invoke(this);

                Destroy(gameObject);
            }
        }
Exemple #20
0
        /// <summary>
        /// Dies this instance.
        /// </summary>
        protected virtual void Die()
        {
            ResetTarget();
            EffectsInspector.ClearEffects();
            OnDie?.Invoke(this);
            OnStopShowing?.Invoke(this);
            SetSelected(false);
            UpdateSelfTarget(show: false);

            DieFinalize();
        }
Exemple #21
0
    /// <summary>
    /// death event
    /// </summary>
    public IEnumerator Die()
    {
        state = PieceState.Die;
        AnimatorController.ChangeAnimation(PlayerAnimations.Death.ToString());
        yield return(new WaitForSeconds(1f));

        gameBoardManager.map.PutPiece(Vector3Int.RoundToInt(CurrentPosition - offset), null);
        gameObject.SetActive(false);
        OnDie?.Invoke();
        yield break;
    }
        public void Damage(int value)
        {
            m_LifeCount--;

            Respawn();

            if (m_LifeCount <= 0)
            {
                OnDie?.Invoke(this);
            }
        }
Exemple #23
0
    public void Die()
    {
        //		if (type == Type.player && playerControl.isWorld) {
        //			player.transform.position = CheckPointTotalManager.instance.savedPos;
        //			return;
        //		}dieEvent
        //		}dieEvent
        //		}dieEvent

        dieEvent.Invoke();
        if (type == Type.player)
        {
            PlayerControl1.Instance.Die();
            playerControl.hp = 0;
        }

        if (SpawnObjOnDie != null)
        {
            GameObject obj = Instantiate(SpawnObjOnDie, transform.position, Quaternion.identity);
            if (obj.CompareTag("thing"))
            {
                obj.GetComponent <Thing>().TriggerMethod?.Invoke();
            }
        }

        if (dead)
        {
            return;
        }
        dead = true;
        OnDie?.Invoke();
        if (type == Type.enemy)
        {
            goal.enemyCount -= 1;
            hasShield        = false;
            gameObject.GetComponent <Enemy>().EnemyDie();
        }
        if (dieParticle != null)
        {
            Instantiate(dieParticle, transform.position, Quaternion.identity);
        }
        if (isDivedeDead)
        {
            GetComponent <HeadBodySeparation>().Dead(force);
            //print("die");
        }
        ProCamera2DShake.Instance.Shake(0.2f, new Vector2(200f, 200f));
        if (PlayerControl1.Instance.swap.overheadRB != null && PlayerControl1.Instance.swap.overheadRB.gameObject == gameObject)
        {
            PlayerControl1.Instance.swap.DropOverhead();
        }
        StartCoroutine(ScaleDown(0.2f));
    }
Exemple #24
0
    private void Kill()
    {
        if (!m_Alive)
        {
            return;
        }

        m_Alive = false;
        OnDie?.Invoke();
        m_FirstBody.Obliterate();
        Destroy(gameObject);
    }
Exemple #25
0
    private void EndGame(Collider2D collider)
    {
        dead = true;
        transform.DOKill();
        GetComponent <Explodable>()?.explode();
        GetComponent <ExplosionForce>()?.doExplosion(collider.transform.position);
        GetComponent <Rigidbody2D>().Sleep();

        OnDie?.Invoke();

        GameManager.Instance.AttemptChangeState(GameManager.GameState.End);
    }
Exemple #26
0
 public override void Die()
 {
     if (!isDied)
     {
         OnDie?.Invoke();
         if (UnityEngine.Random.Range(0, 3) == 0)
         {
             DropResurses();
         }
         isDied = true;
     }
     base.Die();
 }
Exemple #27
0
 public void takeDamage(int damage)
 {
     health -= damage;
     if (health <= 0)
     {
         OnDie.Invoke();
         GameObject canvas = Resources.Load <GameObject>("DieMessage");
         DisableShoot();
         Instantiate(canvas);
         health = 0;
         Timer.RecordTime();
     }
 }
 public void Hurt(float damage)
 {
     _currentHealthValue -= damage;
     OnChangeHealth?.Invoke(_currentHealthValue);
     if (_currentHealthValue <= 0)
     {
         OnDie?.Invoke();
         if (!gameObject.CompareTag("Player"))
         {
             Destroy(gameObject);
         }
     }
 }
Exemple #29
0
    public void TakeDamage(float damage)
    {
        Debug.Log(gameObject + $" take {damage} damage");
        hp -= damage;
        if (hp <= 0)
        {
            hp = 0;
            onDie?.Invoke(this.gameObject);
            Die();
        }

        onDamaged?.Invoke();
    }
    public void Damage(int damageAmount)
    {
        healthAmount -= damageAmount;
        healthAmount  = Mathf.Clamp(healthAmount, 0, healthAmountMax);

        OnDamage?.Invoke(this, EventArgs.Empty);

        // OK, but still alive?
        if (IsDead())
        {
            OnDie?.Invoke(this, EventArgs.Empty);
        }
    }