Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

AudioSource.PlayClipAtPoint

Discussion in 'Scripting' started by BadSeedProductions, Jul 7, 2015.

  1. BadSeedProductions

    BadSeedProductions

    Joined:
    Dec 26, 2014
    Posts:
    144
    I have a group of gameobjects that are all the same linked prefab, and I want to play a sound when destroyed. At first I just tried audio.play, but it seems that the sound is destroyed as the gameobject is destroyed. After some research I found the function AudioSource.PlayClipAtPoint. It works well for one gameobject specifically, and then it won't work on any others, even if I duplicate the working one. code:

    Code (CSharp):
    1. public AudioClip theSound;
    2.  
    3. public void Damage (){
    4. AudioSource.PlayClipAtPoint(theSound, new Vector3(0,0,0));
    5. }
    Any ideas? Thanks
     
    Last edited: Jul 7, 2015