private void Start() { //Night UI this.ObserveEveryValueChanged(x => x.nightSession.GetActualDifficulty()) .Subscribe(x => { difficulty.text = nightSession.GetActualDifficulty().ToString(); }); this.ObserveEveryValueChanged(x => x.nightSession.GetEnemiesAlive()) .Subscribe(x => { enemiesAlive.text = "Enemies Alive: " + nightSession.GetEnemiesAlive().ToString(); }); //Player UI AmmoCD.maxValue = playerSession.GetTimeToReload(); this.ObserveEveryValueChanged(x => x.playerSession.GetAmmo()) .Subscribe(x => { ammo.text = playerSession.GetAmmo().ToString(); }); this.ObserveEveryValueChanged(x => x.playerSession.GetActualTimeToReload()) .Subscribe(x => { AmmoCD.value = playerSession.GetActualTimeToReload(); }); }
private void Start() { playerSession = FindObjectOfType <PlayerSession>(); this.UpdateAsObservable() .Where(_ => Input.GetMouseButton(0)) .Timestamp() .Where(x => x.Timestamp > timeToNextShot.AddSeconds(playerSession.GetTimeToNextShot()) && playerSession.GetAmmo() > 0) .Subscribe(x => { timeToNextShot = x.Timestamp; fire(); }); this.UpdateAsObservable() .Where(_ => playerSession.GetAmmo() == 0) .ThrottleFirst(TimeSpan.FromSeconds(playerSession.GetTimeToReload())) .Delay(TimeSpan.FromSeconds(playerSession.GetTimeToReload())) .Subscribe(_ => { playerSession.SetAmmo(playerSession.GetMaxAmmo()); }); }