Пример #1
0
        private void Start()
        {
            CurrentHealth.Subscribe(x =>
            {
                if (gameObject.CompareTag("Player"))
                {
                    _audioSource.PlayOneShot(Resources.Load <AudioClip>("SFX/S_Hit01"));
                }

                if (x > _maxHealth)
                {
                    CurrentHealth.Value = _maxHealth;
                }

                if (CurrentHealth.Value <= 0)
                {
                    OnDeath.OnNext(gameObject);
                }
            })
            .AddTo(this);

            OnDeath.Subscribe(HandleDeath);
        }