Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by serenefox · Mar 04, 2013 at 01:37 AM · audiomenuguitextureguibutton

GUI Texture not responding to OnMouseEnter

I have a problem creating a simple pause menu in my game and this is my first time working with GUI. My problem is when I move over the text in the pause menu its not recognizing it, the text doesn't turn red and the buttons don't work. I am using two different scripts I have found on the web, combined and slightly modified them. Does it have anything to do with having to use the "Draw" function? Thanks for reading my question. On a side question for this script when I unpause the game using the Esc key the background music starts over, how do I fix that? Here is the script:

 #pragma strict
 
 
 var pause : boolean = false;
 var resumeGUI : GUITexture;
 private var allAudioSources : AudioSource[];
 resumeGUI.enabled = false;
 
 function Awake() 
 { 
     allAudioSources = FindObjectsOfType(AudioSource) as AudioSource[];
 }
 
  function PauseAllAudio() 
 {
      for(var audioS : AudioSource in allAudioSources) { audioS.Pause(); }
 }
 
 function ResumeAllAudio() 
 {
      for(var audioS : AudioSource in allAudioSources) { audioS.Play(); }
 }
 
 
 function Update()
 {
      if(Input.GetKeyUp(KeyCode.Escape)) 
      {
          if(pause==true)
              {
              pause = false;
              }
          else 
              {
              pause = true;
              } 
          if(pause == true) 
              {
              Time.timeScale = 0.0;
              resumeGUI.enabled = true;
              PauseAllAudio();
              }
          else 
              {
              Time.timeScale = 1.0;
              resumeGUI.enabled = false;
              ResumeAllAudio();
              }
      } 
 }
 
 var isMainMenu=false;
 
 
 function OnMouseEnter()
 {
          //change text color
          guiTexture.color = Color.red;
 }
 
 function OnMouseExit()
 {
 
      //change text color
     guiTexture.color = Color.white;
 }
 
 function OnMouseUp()
 {
      //is this quit
      if (isMainMenu==true) 
     {
         //load main Menu
          Application.LoadLevel("AliensMainMenu");
     }
      else 
     {
           Time.timeScale = 1.0;
          resumeGUI.enabled = false;
          ResumeAllAudio();
     }
 }    


Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eric5h5 · Mar 04, 2013 at 03:15 AM 0
Share

@robertbu: On$$anonymous$$ouse* functions work perfectly fine with GUIElements. They don't need colliders.

avatar image robertbu · Mar 04, 2013 at 03:19 AM 0
Share

Thanks Eric. I was visualizing the GUI.* calls, but that's clearly not what he is using.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Chronos-L · Mar 04, 2013 at 01:57 AM

Can you post a screenshot? I am not sure how many gui element you have right now (i think there are 1 pause and 1 resume), and what gameObject you are attaching this script to? (empty, guiTexture, guiText or something else)

Answer to side question

Answered question in UnityAnswers : Continueing music after un-pausing

Edit (3rd Rev)

In Unity's documentation on OnMouseOver, your overwritten version of OnMouseOver() is called every time your mouse is over the GUIElement or Collider this script is attached to. However, in your case, you attach it to the camera (which is neither GUIElement or Collider).

In your question, you said that you combined and modify 2 scripts, so I am quite sure that all the OnMouse function are from 1 script. What you should do now is to make it 2 script again ( I throw in a few lines to allow communication between 2 scripts ).

Proposed Solution

Pause Script (Attach to camera or empty object)

 #pragma strict
   
 var pause : boolean = false;
 var clickTexture : ClickTexture[];
 private var allAudioSources : AudioSource[];
  
 function Awake() 
 { 
     EnableClick( false );
     
     for( var i : int = 0; i < clickTexture.Length; ++i ) 
       clickTexture[i].pauseScript = this;
 
     allAudioSources = FindObjectsOfType(AudioSource) as AudioSource[];
 }
  
  function PauseAllAudio() 
 {
     for(var audioS : AudioSource in allAudioSources) { audioS.Pause(); }
 }
  
 function ResumeAllAudio() 
 {
     //ResumeAllAudio is not fixed
     for(var audioS : AudioSource in allAudioSources) { audioS.Play(); }
 }
  
  
 function Update()
 {
      if(Input.GetKeyUp(KeyCode.Escape)) 
      {
         //Super lazy one-liner
         pause = !pause; 
 
         if(pause == true) 
         {
           Time.timeScale = 0.0; 
           EnableClick( true );        
           PauseAllAudio();
         }
         else 
         {
           Time.timeScale = 1.0;
           EnableClick( false );    
           ResumeAllAudio();
         }
      } 
 }
 
 function RunOption( str : String ) {
    if( str == "quit" ) {
        Application.LoadLevel("AliensMainMenu");
    }
    else if( str == "resume" ) {
       Time.timeScale = 1.0;
       EnableClick( false );    
       ResumeAllAudio();
    }
 }
 
 function EnableClick( b : boolean ) {
    for( var i : int = 0; i < clickTexture.Length; ++i ) 
        clickTexture[i].Show(b);
 }

ClickTexture Script (Attach to GUITextre/GUIText)

 var pauseScript : Pause;
 var optionString : String;
 
 function OnMouseEnter()
 {
        //change text color
        guiTexture.color = Color.red;
 }
  
 function OnMouseExit()
 {
  
      //change text color
     guiTexture.color = Color.white;
 }
  
 function OnMouseUp()
 {
     pauseScript.RunOption( optionString );
 }

 function Show( b : boolean ) {
     this.enabled = b;
 
     if( guiTexture ) {
         guiTexture.enabled = b;
     }
 
     if( guiText ) {
         guiText.enabled = b;
     }
 }

Comment
Add comment · Show 12 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image serenefox · Mar 04, 2013 at 02:29 AM 0
Share

alt text

Yeah I have two options in the pause menu, Resume and Quit To $$anonymous$$enu. I have attached it to the $$anonymous$$ain Camera which is labeled camera. and thank you for the answer to my other question. the two options are supposed to turn red when I hover over them with the mouse but its not detecting that.

screenshot.jpg (396.8 kB)
avatar image Chronos-L · Mar 04, 2013 at 03:03 AM 0
Share

Look at my answer again. I added in my answers for your main question.

avatar image serenefox · Mar 04, 2013 at 05:05 AM 0
Share

Thanks for the reply but its showing errors for lines 11 and 13 in the first script and it wont let me do anything. i cant figure out what the errors are telling me because it looks right.

the 3 errors are :

Assets/Scripts/Pause$$anonymous$$enu.js(11,18): BCE0044: expecting ;, found 'i'.

Assets/Scripts/Pause$$anonymous$$enu.js(11,54): BCE0043: Unexpected token: ).

Assets/Scripts/Pause$$anonymous$$enu.js(13,42): BCE0044: expecting :, found '='.

avatar image Chronos-L · Mar 04, 2013 at 06:08 AM 0
Share

Sorry, I was using C# syntax ( I start Unity with JS, then I switch to C# later, so I just type in C# unconsiously ). I compile the script in my Playground project, and I fix some of the syntax.

Look at my answer again.

I fixed the following:

  • Line 11 : for( int i = 0; ..., syntax error

  • Line 12 : clickTexture., forgot to use index

  • Line 51 : function RunOption( string str ), syntax error

  • Line 62 : function EnableClick( bool b ), syntax error

  • Line 63 : Same error as line 11

  • Line 64 : Same mistake as line 12

avatar image serenefox · Mar 04, 2013 at 06:24 AM 0
Share

Thank you I am soooo close but I have one error now:

Assets/Scripts/ClickTexture.js(3,19): BCE0018: The name 'Pause' does not denote a valid type ('not found').

Also I thought that might have been the problem with the different syntax but i didn't get around to trying to change the scripts. But thank for showing me the javascript version.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making a GUITexture Menu proportional to screen resolution 0 Answers

Menu music stops playing after returning from game level 0 Answers

Animate GUI Elements 1 Answer

How to make menu which is able to list audio files, then load chosen one into the AudioSource in the scene 1 Answer

Problem with UI in iOS / Android 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges