- Home /
 
Playing a sound clip from another object
I've been trying to play a sound file attached to the door gameobject via a controller, a god x) , script.
 public GameObject door;
 void Update()
 {
  if(done == 1) //some condition
  {
   door.audio.play(/*need the name of clip here*/);
   // also PlayOneShot doesn't seem to get it right, If I could reference the string
   // in it
  }
 }
 
              Answer by KMKxJOEY1 · Apr 01, 2013 at 11:31 AM
 AudioClip sound = door.GetComponent<door_script>().getsound();
 
               And in the door script:
 public AudioClip getsound()
 {
 return sound;
 }
 
               Sound is the AudioClip variable of the door sound
I am little confused, my door gonna 2 audio files, how could it be possible since the audiosource only take 1 file and if the file is played from the controller script won't the 3D sound come from controller and not the door? It would sound weird maybe 0 as the controller(an empty gameobject) would not be near the player.
alright I think I got it, btw how would you play the sound clip finally ? Cause it says the value of sound is assigned but never used
Your answer
 
             Follow this Question
Related Questions
Set audio clip to 3D in script 1 Answer
Music works but not when accessed by another script in JavaScript 1 Answer
Get audio from device... -1 Answers
Help with sound clips [C#] 0 Answers
Random, 3d sound. 1 Answer