Ejemplo n.º 1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        IDie dieObject = collision.GetComponent <IDie>();

        if (dieObject != null)
        {
            dieObject.Die();
        }
    }
Ejemplo n.º 2
0
    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;
        }
    }
Ejemplo n.º 3
0
    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);
    }
Ejemplo n.º 4
0
 private void Die()
 {
     deathBehavior.Die();
 }