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
 }
}

1 Answer

1

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

–

audio.PlayOneShot(sound);

–