AudioSource dissappears in variable window on Play
I have a script that is supposed to play an audio clip once the player enters a trigger. My script is very closely based upon the one in the Scripting API. I have watched tutorials as well and they have scripts that are the same as the one in the API.
#pragma strict
public var leaves: AudioSource;
function Start(){
leaves = GetComponent.<AudioSource>();
}
function OnTriggerEnter(col : Collider) {
if(col.gameObject.name == "First Person"){
leaves.Play();
}
}
The source's volume is up, and there is a clip attached to it. The fact that I have it looking for a specific collider doesn't cause any issues because I've troubleshot that already.
I have the source drag/dropped into the variable window on the script.
Though once I hit the Play button, the audio source dissappears from the variable window. I can drag the audio source back into it while in play and the script works perfectly. Yet, nothing saves when in play mode.
To the best of my knowledge, I'm doing everything correctly. I just wonder if there's something in the script causing the audio source to be removed, or a setting in the editor perhaps.
Thanks for the help!
Answer by Freshlies · Jan 08, 2016 at 03:42 AM
I realized what was wrong. The AudioSource needed to be a component of the trigger instead of a separate game object. smh
Thanks for your help!
Hiii @Freshlies can I ask for a detailed solution? I have the same problem right now. Thankee
Your answer
Follow this Question
Related Questions
Performance Issue While Near One Specific Object 0 Answers
change Volume of Audiomixergroups by script 1 Answer
Question on Audio? 1 Answer
Change Audio Mixer through script for every scene 0 Answers
OnTriggerExit does not work 0 Answers