private void OnTriggerEnter2D(Collider2D collision) { IDie dieObject = collision.GetComponent <IDie>(); if (dieObject != null) { dieObject.Die(); } }
public void Reset(int hp) { Debug.Log("Enemy SetHP: " + hp); if (hp > _MaxHP) { return; } if (hp < 0) { _iDie.Die(_transform.localPosition.ToPos()); return; } if (_hpParent != null) { GameObject.Destroy(_hpParent.gameObject); } _hpParent = (new GameObject()).transform; _hpParent.name = "HP Parent"; // TODO need to be optimized _hpParent.SetParent(_transform); _hpParent.localPosition = Vector3.zero; _hpParent.localEulerAngles = Vector3.zero; float x = 0 - (int)(_MaxHP / 2f) * _hpDisplayGap; float y = 0.35f; for (int i = 0; i < hp; ++i) { Transform tf = GameObject.Instantiate(GameData._Instance._hitPointPrefab); tf.SetParent(_hpParent); tf.localPosition = new Vector3(x, y); x += _hpDisplayGap; } _curHP = hp; // 先扣血再说,然后判定是否死亡 if (hp == 0) { _iDie.Die(_transform.localPosition.ToPos()); return; } }
public void TakeDamage(float damageAmount) { // Reduced the health with the damage taken. currentHealth -= damageAmount; currentHealthPct = currentHealth / health; if (currentHealth <= 0) { objectToDie.Die(); currentHealth = 0; } // Calls the event saying that the health changed and gives a new percentage // to whomever is registered for the info. OnHealthChanged(currentHealthPct); }
private void Die() { deathBehavior.Die(); }