private void Start() { actualSession = FindObjectOfType <NightSession>(); this.UpdateAsObservable() .Subscribe(_ => { avaiableWaves = FilterWaves(); }); this.UpdateAsObservable() .Where(_ => avaiableWaves.Count > 0) .ThrottleFirst(TimeSpan.FromSeconds(cooldown)) .Delay(TimeSpan.FromSeconds(cooldown)) .Subscribe(_ => { if (SceneManager.GetActiveScene().name == "MainGame") { //Get random avaiable Wave to get the enemies from it int selectedWave = UnityEngine.Random.Range(0, avaiableWaves.Count); List <Enemy> enemies = avaiableWaves[selectedWave].getEnemies(); //Update Game Session actualSession.AddEnemiesAlive(enemies.Count); actualSession.AddActualDifficulty(Waves[selectedWave].getDifficulty() * -1); //Spawn enemies SpawnEnemies(enemies); } }); }
private void Start() { name = Name; gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(Velocity * -1, 0) * Time.deltaTime; nightSession = FindObjectOfType <NightSession>(); ActualHealth = Health; this.ObserveEveryValueChanged(x => x.Health) .Subscribe(_ => { HealthText.text = Health.ToString("F0"); }); this.OnTriggerEnter2DAsObservable() .Subscribe(x => { Arrow arrow = x.gameObject.GetComponent <Arrow>(); if (arrow) { AddHealth(arrow.GetDamage() * -1); //Remove Health because is causing Damage to the enemy if (Health <= 0f) { Die(); } //Debug.LogFormat("{0} was hit by {1} with {2} Damage", gameObject.name, arrow.name, arrow.GetDamage().ToString()); } }); }
void Awake() { nightSession = FindObjectOfType <NightSession>(); playerSession = FindObjectOfType <PlayerSession>(); if (!nightSession || !playerSession) { SceneManager.LoadScene("MainMenu"); } }