Hello, I am quite new to Unity and doing small project for school and I am quite stuck. What I need is to play two sound files after I click button. One is casting effect and other is spell effect sound which will play 1.5s after pressing button. Problem with my script is that it only plays first AudioClip but not second. Unity is throwing me error IndexOutOfRangeException: Array index is out of range. for lines 15 and 32 (audios[1].clip = clips[1]; and audios[1].PlayOneShot (clips[1]));. Can anyone help me?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
[RequireComponent(typeof(AudioSource))]
public class Heal : MonoBehaviour {
public AudioClip[] clips;
private AudioSource[] audios;
void Start () {
audios = GetComponents<AudioSource> ();
audios[0].clip = clips[0];
audios[1].clip = clips[1];
}
void Update() {
if (Input.GetKeyDown (KeyCode.W)) {
StartCoroutine (WaterEffect());
}
}
public void WaterEffectClick() {
StartCoroutine (WaterEffect());
}
public IEnumerator WaterEffect() {
audios[0].PlayOneShot (clips[0]);
yield return new WaitForSeconds(1.5f);
audios[0].Stop ();
audios[1].PlayOneShot (clips[1]);
}
}