Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

C#: How to pause OnMouseOver and audio?

Discussion in 'Scripting' started by RayDawg, Dec 5, 2014.

  1. RayDawg

    RayDawg

    Joined:
    Mar 19, 2013
    Posts:
    108
    I have cubes that are instantiated multiple times (at random amounts) each with an attached script that will change the renderer color and play a sound via OnMouseOver . I have another object that will set the timescale to 0 when the escape button is pressed to "pause" the game. However, the cubes will still change color and play a sound when the mouse is over them. How would I get these cube objects to stop playing a sound and changing renderer color when I have the game "paused?"
     
  2. sterynkng14

    sterynkng14

    Joined:
    Sep 19, 2013
    Posts:
    36
    I would add in a condition for the events following mouseover

    Code (CSharp):
    1. if(Time.timeScale != 0)
    2. {
    3.      //Change color and play sound
    4. }
    5. else
    6. {
    7.      //Pause or Stop the music
    8. }
    9.  
     
    TengoChuches likes this.
  3. RayDawg

    RayDawg

    Joined:
    Mar 19, 2013
    Posts:
    108
    It worked great, thanks!
     
  4. sterynkng14

    sterynkng14

    Joined:
    Sep 19, 2013
    Posts:
    36
    Absolutely no problem. I am glad I could help.
     
  5. TengoChuches

    TengoChuches

    Joined:
    Apr 26, 2022
    Posts:
    1
    Thanks for that, ur reply is still working in 2022 :D