private AudioSource[] sirens; // Reference to the AudioSources of the megaphones. void Awake() { // Setup the reference to the AudioSource. _audio = GetComponent <AudioSource>(); // Setup the reference to the alarm light. alarm = GameObject.FindGameObjectWithTag(DoneTags.alarm).GetComponent <DoneAlarmLight>(); // Setup the reference to the main directional light in the scene. mainLight = GameObject.FindGameObjectWithTag(DoneTags.mainLight).GetComponent <Light>(); // Setup the reference to the additonal audio source. panicAudio = transform.Find("secondaryMusic").GetComponent <AudioSource>(); // Find an array of the siren gameobjects. GameObject[] sirenGameObjects = GameObject.FindGameObjectsWithTag(DoneTags.siren); // Set the sirens array to have the same number of elements as there are gameobjects. sirens = new AudioSource[sirenGameObjects.Length]; // For all the sirens allocate the audio source of the gameobjects. for (int i = 0; i < sirens.Length; i++) { sirens[i] = sirenGameObjects[i].GetComponent <AudioSource>(); } }
private AudioSource[] sirens; // Reference to the AudioSources of the megaphones. void Awake () { // Setup the reference to the alarm light. alarm = GameObject.FindGameObjectWithTag(DoneTags.alarm).GetComponent<DoneAlarmLight>(); // Setup the reference to the main directional light in the scene. mainLight = GameObject.FindGameObjectWithTag(DoneTags.mainLight).light; // Setup the reference to the additonal audio source. panicAudio = transform.FindChild("secondaryMusic").audio; // Find an array of the siren gameobjects. GameObject[] sirenGameObjects = GameObject.FindGameObjectsWithTag(DoneTags.siren); // Set the sirens array to have the same number of elements as there are gameobjects. sirens = new AudioSource[sirenGameObjects.Length]; // For all the sirens allocate the audio source of the gameobjects. for(int i = 0; i < sirens.Length; i++) { sirens[i] = sirenGameObjects[i].audio; } }