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
파일: Health.cs 프로젝트: swet-s/Dark
 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;
     }
 }