UhOhUFellScript.cs (2017B)
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 5 public class UhOhUFellScript : MonoBehaviour { 6 7 // Use this for initialization 8 public GameObject[] slime; 9 private bool[] running; 10 SpawnManagerV2 spawnManager; 11 12 void Awake() 13 { 14 Debug.Log("FallScriptStart!!!"); 15 spawnManager = GameObject.Find("SpawnManager").GetComponent<SpawnManagerV2>(); 16 slime = spawnManager.spawnedPlayers.ToArray(); 17 running = new bool[PublicStatHandler.GetInstance().amountOfPlayers]; 18 } 19 20 // Update is called once per frame 21 void Update () { 22 for (int i = 0; i < PublicStatHandler.GetInstance().amountOfPlayers; i++) { 23 if (slime[i].transform.position.y <= -20 && !running[i]) { 24 25 if (AudioManager.getInstance() != null) 26 { 27 AudioManager.getInstance().Find("fall").source.Play(); 28 } 29 30 StartCoroutine(WaitAndRespawn(i, 1f)); 31 32 } 33 } 34 } 35 36 private IEnumerator WaitAndRespawn(int i, float respawnTime) 37 { 38 running[i] = true; 39 yield return new WaitForSeconds(respawnTime); 40 41 if (AudioManager.getInstance() != null && !AudioManager.getInstance().Find("fall").source.mute) 42 { 43 AudioManager.getInstance().Find("fall").source.Stop(); 44 } 45 46 StartCoroutine(PlayRespawn(0.2f)); 47 48 spawnManager.ResetUseableSpawns(); 49 slime[i].transform.position = spawnManager.SelectSpawnPoint().position; 50 slime[i].GetComponent<Rigidbody>().velocity = Vector3.zero; 51 slime[i].GetComponent<PlayerMovement>().slimePercentage = 0; 52 slime[i].GetComponent<PlayerMovement>().health--; 53 running[i] = false; 54 } 55 56 private IEnumerator PlayRespawn(float wait) 57 { 58 yield return new WaitForSeconds(wait); 59 if (AudioManager.getInstance() != null) 60 { 61 AudioManager.getInstance().Find("respawn").source.Play(); 62 } 63 } 64 }