Hello,
I have 2 AudioSources on my GameObjects and trying to set their clip automatically by their type but with no success yet:
private var aud : AudioSource[] = new AudioSource[2];
private var a_horn : AudioSource;
private var a_engine : AudioSource;
function Start (){
aud = GetComponents(AudioSource);
a_horn = aud[0];
a_engine = aud[1];
if(transform.FindChild("Police")){
a_horn.clip = Resources.Load("Sounds/PoliceHorn") as AudioClip;
} else if(transform.FindChild("Boat")){
a_horn.clip = Resources.Load("Sounds/BoatHonk") as AudioClip;
}
}
Everytime it gives me an “InvalidCastException: Cannot cast from source type to destination type.” Error