Search Unity

I can't play sound

Discussion in 'Scripting' started by mohammad7484, Nov 29, 2012.

  1. mohammad7484

    mohammad7484

    Joined:
    Nov 29, 2012
    Posts:
    2
    Hi ;
    I am beginner in unity .
    I want to play a sound which it is in 'Sounds' folder in assets . I tried this code :
    Code (csharp):
    1.  
    2. audio.Play(kick2);
    3.  
    but I got this error : Unknown Identifier 'kick2'

    I don't know how to address to find it in Sound folder .

    I tried these syntaxes but I got error too .
    audio.Play(My Assets/Sounds/kick2)
    and
    audio.Play('My Assetes/Sounds/kick2')
    and ...

    Please say the correct syntax ...
    thanx ;)
     
  2. john-essy

    john-essy

    Joined:
    Apr 17, 2011
    Posts:
    464

    What you want to do is create a variable that will hold your sound "Kick2" Like this

    Code (csharp):
    1. public var kick2 : AudioClip;
    2.  
    3. public function PlaySound()
    4. {
    5.       Audio.Play(kick2);
    6. {
    C# version

    Code (csharp):
    1. public AudioClip kick2;
    2.  
    3. public void PlayAudioClip()
    4. {
    5.      Audio.Play(kick2);
    6. }
     
  3. mohammad7484

    mohammad7484

    Joined:
    Nov 29, 2012
    Posts:
    2


    Thank you ,
    But I got this error :
    BCE0017: The best overload for the method 'UnityEngine.AudioSource.Play()' is not compatible with the argument list '(UnityEngine.AudioClip)'.