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);
            }
        }
    }
Пример #2
0
        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);
        }
Пример #3
0
    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);
        }
    }
Пример #4
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;
        }
Пример #5
0
    // 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();
            }
        }
    }
Пример #6
0
 public void Kill()
 {
     motor.animator.SetBool("Character/Dead", true);
     motor.animator.CrossFadeInFixedTime("Die", 0.2f);
     Destroy(GetComponent <Target>());
     OnDie?.Invoke();
 }
Пример #7
0
 private void Die()
 {
     OnDie?.Invoke(this);
     Gamemanager.instance.OnEnemyDieHandler(pointsToGive, extraTime);
     Gamemanager.instance.enemiesController.ItemToDrop(this.transform.position, chanceToSpawnItem);
     Destroy(this.gameObject);
 }
Пример #8
0
        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 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();
        }
    }
Пример #10
0
	// Use this for initialization
	void Start () {
    
        HP = startHP;
        SP = startSP;
        Die += TryNavMeshAgent.instance.Dead;
        SetHp();
        SetSp();
	}
Пример #11
0
    private IEnumerator Die()
    {
        yield return(new WaitForNote(Note.Quarter, 3));

        bloodSpurtVfx.Stop();
        bloodSpurtVfx.Destroy();
        OnDie?.Invoke(this);
    }
Пример #12
0
 void EndDie()
 {
     Animator.ResetTrigger(DeathHash);
     Animator.SetTrigger(DeadHash);
     Collider.enabled = false;
     UpdateParams();
     OnDie?.Invoke();
 }
Пример #13
0
 private void Update()
 {
     if (transform.position.sqrMagnitude >= 20000)
     {
         OnDie?.Invoke(this);
         Destroy(gameObject);
     }
 }
Пример #14
0
 public void Die()
 {
     if (!IsDead)
     {
         IsDead = true;
         arena.Kill(this);
         OnDie.Invoke();
     }
 }
Пример #15
0
        private IEnumerator WaitForAnimationToEnd()
        {
            OnDie?.Invoke();
            RigidBody2D.velocity = Vector2.zero;
            yield return(new WaitForSeconds(1.67f));

            OnResetLevel?.Invoke();
            ResetPlayer();
        }
Пример #16
0
 private void OnDisable()
 {
     if (!ZombiesManager.Singleton.gameOver)
     {
         if (OnDie != null)
         {
             OnDie.Invoke();
         }
     }
 }
    private void Die()
    {
        OnDie?.Invoke();

        birdMovement.ResetVelocity();
        visualTransform.localEulerAngles = new Vector3(
            visualTransform.localEulerAngles.x,
            visualTransform.localEulerAngles.y,
            -90);
    }
Пример #18
0
        public void Damage(int value)
        {
            m_LifeCount--;

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

                Destroy(gameObject);
            }
        }
Пример #19
0
        public void Damage(int value)
        {
            m_LifeCount--;

            Respawn();

            if (m_LifeCount <= 0)
            {
                OnDie?.Invoke(this);
            }
        }
Пример #20
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;
    }
Пример #21
0
        private void Die()
        {
            OnDie?.Invoke();

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

            Invoke(nameof(EndGame), 1);
        }
Пример #22
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();
        }
Пример #23
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);
    }
Пример #24
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));
    }
Пример #25
0
        /// <summary>
        /// Returns this object to the object pool.
        /// </summary>
        public virtual void DestroyAsPoolableObject()
        {
            if (OnDie != null)
            {
                foreach (Action <IDying> handler in OnDie.GetInvocationList())
                {
                    OnDie -= handler;
                }
            }

            OnDestroyAsPoolableObject?.Invoke(this);
        }
Пример #26
0
    private void Kill()
    {
        if (!m_Alive)
        {
            return;
        }

        m_Alive = false;
        OnDie?.Invoke();
        m_FirstBody.Obliterate();
        Destroy(gameObject);
    }
Пример #27
0
 public override void Die()
 {
     if (!isDied)
     {
         OnDie?.Invoke();
         if (UnityEngine.Random.Range(0, 3) == 0)
         {
             DropResurses();
         }
         isDied = true;
     }
     base.Die();
 }
Пример #28
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 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);
        }
    }
Пример #30
0
 public void Hurt(float damage)
 {
     _currentHealthValue -= damage;
     OnChangeHealth?.Invoke(_currentHealthValue);
     if (_currentHealthValue <= 0)
     {
         OnDie?.Invoke();
         if (!gameObject.CompareTag("Player"))
         {
             Destroy(gameObject);
         }
     }
 }
Пример #31
0
 private void Respawn()
 {
     OnDie?.Invoke();
     if (GameManager.playerHealth <= 0)
     {
         // play death animation screen, disable movement
         GameManager.inGame = false;
         Invoke(nameof(ReloadLevel), 2f);
     }
     else
     {
         transform.position = respawnPoint;
     }
 }