Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

what function call by update ?

Discussion in 'Scripting' started by athgen113, Aug 11, 2018.

  1. athgen113

    athgen113

    Joined:
    May 25, 2018
    Posts:
    37
    my game is over when tranfrom.possition.y<3f and i add in function Update but now i want add audio.playoneshot ,it not work by update alway call . how can i fix
     
  2. athgen113

    athgen113

    Joined:
    May 25, 2018
    Posts:
    37
    @Doug_B can you help me ,i fix done my ads ^^
     
  3. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,403
    Excellent news! Well done. :D

    If I understand you correctly, you want to play a sound when the game is over. You only want the sound to play once. Is that correct?

    If so, then you could add
    bool m_hasEndMusicPlayed;
    and only play the audio if that value is false (obviously set it to true when playing the audio for the first time).
     
  4. athgen113

    athgen113

    Joined:
    May 25, 2018
    Posts:
    37
    thank you so much , so how play audio music ? when i play music on , and if(tranfrom.positon.y<3f){ music off , dead audio on} ?
     
  5. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,403
    You just need to follow the Unity instructions on how to do this. You should have an audio listener attached to your main camera by default which will pick up the audio when it is played.
     
  6. athgen113

    athgen113

    Joined:
    May 25, 2018
    Posts:
    37
    thank you ,i did . i use a variable bool to check and it work ^^
     
    Doug_B likes this.