Example #1
0
        private void Start()
        {
            playerPicture = GameObject.FindWithTag(TagsHelper.PlayerTag);
            player        = playerPicture.GetComponent <IHittable>();

            player.Hp.ObserveEveryValueChanged(x => x.Value)
            .Subscribe(healthUi.UpdateHealth)
            .AddTo(healthUi.gameObject);
            GameController.StaticObject.ScoreKilled.ObserveEveryValueChanged(x => x.Value)
            .Subscribe(scoreUi.UpdateScore)
            .AddTo(scoreUi.gameObject);

            player.IsDead.ObserveEveryValueChanged(x => x.Value).Where(x => x == true)
            .Subscribe(x => GameController.StaticObject.IsGameOver.Value = true)
            .AddTo(GameController.StaticObject);

            GameController.StaticObject.IsGameOver.ObserveEveryValueChanged(x => x.Value)
            .Subscribe(xs => {
                if (xs)
                {
                    gameOverUi.GameOverShow(GameController.StaticObject.LevelComplete.Value);
                    playerPicture.SetActive(false);
                }
            })
            .AddTo(gameOverUi.gameObject);

            GameController.StaticObject.SpecifiedTime.ObserveEveryValueChanged(x => x.Value)
            .Subscribe(x => timerUi.UpdateTimer(x))
            .AddTo(timerUi.gameObject);
        }
Example #2
0
    private void UpdateTimer()
    {
        if (currentState == GameState.INPROGRESS)
        {
            timeRemaining -= Time.deltaTime;

            if (timeRemaining <= 0f)
            {
                spawnSystem.StopSpawning();

                // FindGameObjectWithTag is very spooky when in the Update method so let's avoid it in the future
                // if(GameObject.FindGameObjectWithTag("NPC") == null) EndRound(true);

                if (!spawnSystem.HasNPCs())
                {
                    EndRound(true);
                }
            }

            timeRemaining = Mathf.Clamp(timeRemaining, 0f, Mathf.Infinity);
            dynamicSky.UpdateSky(timeRemaining / roundTimer);
            timerUI.UpdateTimer(timeRemaining);
        }
    }
Example #3
0
 private void Update()
 {
     currentTimer = Time.time - startTime;
     timerUI.UpdateTimer(currentTimer);
 }