// Update is called once per frame void Update() { // Keep track of time elapsedTime += Time.deltaTime; // When the next station is reached if (elapsedTime >= TripDuration) { // Select alien to get off //int index = Random.Range(0, InTrain.Count); int index = SelectAlienToGetOff(); AwareAlien outAlien = InTrain[index]; outAlien.gameObject.SetActive(false); InTrain.RemoveAt(index); Used.Add(outAlien); // Trigger puff Puff.Instance.Explosion(outAlien.transform.position); // Select alien to get in index = Random.Range(0, Unused.Count); AwareAlien inAlien = Unused[index]; inAlien.gameObject.SetActive(true); Unused.RemoveAt(index); InTrain.Add(inAlien); // Move used to unused unused is empty if (Unused.Count == 0) { Unused.AddRange(Used); Used.Clear(); } // Reset timer elapsedTime = 0; //Debug.Log("Station reached"); } }
// Use this for initialization void Start() { // Reset background index backgroundIndex = 0; // Reset timer elapsedTime = 0; // Pick initial monsters from unused list // First alien int index = Random.Range(0, Unused.Count); AwareAlien alien1 = Unused[index]; alien1.gameObject.SetActive(true); Unused.RemoveAt(index); InTrain.Add(alien1); // Second alien index = Random.Range(0, Unused.Count); AwareAlien alien2 = Unused[index]; alien2.gameObject.SetActive(true); Unused.RemoveAt(index); InTrain.Add(alien2); }