- Home /
How to find audioclip in scene
I've looked it up, and can't figure it out.
I have an audio clip in the scene, not attached to anything.
My code is like:
public var powerUpSound: AudioClip;
function Start (){
powerUpSound = Transform.Find("Power Up");
// I also tried...
powerUpSound = AudioClip.Find("Power Up);
//and
powerUpSound = GameObject.Find("Power Up");
}
both are a no go. I can't add it in the inspector because of static issues... this would make it much easier to just find it in the scene. I've added the audio clip to the scene.
There is no AudioClip in a scene. It would be attached to an AudioSource which is in the scene. You declare var powerUpAudio but you are trying to set powerUpSound, typo? What static issues? And what exactly are you trying to do?
I fixed the Audio/Sound typo, that typo isn't in my code. What I am trying to do is when I shoot an enemy, my character gets powered up and the sound effect is so that the player knows they are powered up (just in case they missed it).
The function I am calling is a static function, and it says that "audio.PlayOneShot(powerUpSound)" won't work. I get an error. I think Im just going to skip this, it's hard to explain, but thanks for the help.
I'm going to make a new gameobject (AudioSource) and attach the AudioClip to that and see if that works. If not, the player better be paying attention when they power up.
Thanks again