private void OnTriggerEnter2D(Collider2D other)
    {
        if (!other.transform.CompareTag("Enemy"))
        {
            return;
        }

        if (--_currentLives < 1)
        {
            OnHouseDestroy?.Invoke();
        }

        CanvasGroup heartCanvasGroup;

        switch (_currentLives)
        {
        case 0:
            heartCanvasGroup = heart1;
            break;

        case 1:
            heartCanvasGroup = heart2;
            break;

        case 2:
            heartCanvasGroup = heart3;
            break;

        default:
            heartCanvasGroup = heart1;
            break;
        }

        heartCanvasGroup.alpha = 0f;
    }
示例#2
0
        private void Die()
        {
            if (_died)
            {
                return;
            }

            _died = true;
            GameObject explosion = Instantiate(_explosionPrefab);

            explosion.transform.position = transform.position + new Vector3(0f, 0f, -0.7f);
            _audio.PlayOneShot(_explosionClip);
            OnHouseDestroy?.Invoke(_position);
            _scene.HouseGenerator.DestroyHouse(this._position);
        }