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

Problem with sounds, please help!

Discussion in 'Scripting' started by Dari, Nov 1, 2013.

  1. Dari

    Dari

    Joined:
    Mar 25, 2013
    Posts:
    130
    I have this script (it's only part of one), and it won't work. I want to stop the sound but it says some errors.

    Script:

    Code (csharp):
    1. if(sound){
    2. if(Input.GetMouseButtonDown(0)  enter  open){
    3. AudioSource.PlayClipAtPoint(openSound, transform.position);
    4. audio.clip = closeSound;
    5. audio.Stop(closeSound); //line 42
    6. }
    7.  
    8. if(Input.GetMouseButtonDown(0)  enter  !open){
    9. AudioSource.PlayClipAtPoint(closeSound, transform.position);
    10. audio.clip = openSound;
    11. audio.Stop(openSound); //line 48
    12. }
    13.  
    14. if(Input.GetMouseButtonDown(0)  locked  enter2){
    15. AudioSource.PlayClipAtPoint(lockedSound, transform.position);
    16. }
    17. }


    Errors:

    Please help! Thanks in advance! :)
     
  2. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    Just type

    audio.Stop();

    instead of audio.Stop("nameOfSound")
     
  3. novashot

    novashot

    Joined:
    Dec 12, 2009
    Posts:
    373
    Audio.stop () takes no arguments.... it just stops that audio source.
     
  4. Brian-Stone

    Brian-Stone

    Joined:
    Jun 9, 2012
    Posts:
    222
  5. Dari

    Dari

    Joined:
    Mar 25, 2013
    Posts:
    130
    Thanks a lot guys... That was pretty dumb mistake though.