Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    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. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Don't miss out on the Unite LA Keynote for the latest information from Unity! Set a reminder!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    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,395
    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,395
    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.