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 Lasset · Feb 19, 2013 at 06:03 PM · guiclickonguionmousedown

Display message when OnMouseDown

Hello guys,

I have been searching how to display a message replacing the Debug.Log (code below) for a GUI during 2 seconds and then hide it. The research conducted has pointed out that I should create a boolean but when I try with the following code, I have an error that says "Return type 'void' cannot be used on a generator. Did you mean 'IEnumerator'? You can also use 'System.Collections.IEnumerable' or 'object'.. " Also, the object clicked is not destroyed.

Thank you in advance for your help.

 var object: GameObject;
 var information: String = "Well done";
 var guiOn = false;
 private var rect: Rect;
 
 
     
     function OnMouseDown():void
     { 
         var clickedTag:String = gameObject.tag;
      
         if(Inventory.objectToBeFound == 1) selected = true;
         
         guiOn = true; 
         rect = Rect(Input.mousePosition.x, Input.mousePosition.y, 300, 100);
         yield WaitForSeconds(5);
         guiOn = false;
         
         start.score += 100;
         Debug.Log("Well done!"); 
         Destroy(gameObject);
         
         if(Inventory.objectToBeFound != 1) {
         Debug.Log("incorrect object");
         }
     }
   
 function OnGUI(){
     if (guiOn){
         GUI.Label(rect, information);
     }
 }
 
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Feb 19, 2013 at 06:30 PM

Remove the ':void' in this statement:

 function OnMouseDown():void

The rest of the code looks like it should work.

Comment
Add comment · 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
0

Answer by Lasset · Feb 19, 2013 at 07:36 PM

Thanks for the fast answer. You're right, the error disappears and I get the display message in the first "if". Do you know how can I generate another message for the second "if"? I have tried the code below but didn't work.

Thanks!

 var object: GameObject;
 var information: String = "Well done";
 var information2:  String = "incorrect object";
 var guiOn = false; 
 var guiOn2 = false;
 private var rect: Rect;
  
     function OnMouseDown()
     { 
         var clickedTag:String = gameObject.tag;
  
         if(Inventory.objectToBeFound == 1) selected = true;
  
         guiOn = true; 
         rect = Rect(Input.mousePosition.x, Input.mousePosition.y, 300, 100);
         yield WaitForSeconds(5);
         guiOn = false;
  
         HudGame.score += 100;
         Debug.Log("Well done!"); 
         Destroy(gameObject);
  
         if(Inventory.objectToBeFound != 1) { 
         guiOn2 = true; 
         rect = Rect(Input.mousePosition.x, Input.mousePosition.y, 300, 100);
         yield WaitForSeconds(5);
         guiOn2 = false;
         Debug.Log("incorrect object");
         }
     }
  
 function OnGUI()
 {
     if (guiOn) {
         GUI.Label(rect, information);
     }
     if (guiOn2) { 
     GUI.Label(rect, information2);
     }
 }
Comment
Add comment · Show 2 · 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 robertbu · Feb 19, 2013 at 07:47 PM 0
Share

Answers should be reserved for potential answer to your question. Use the "add new comment" button below your question to add new material.

As for your problem. You destroy your game object on line 21, so the rest of your code will not execute. I'm not sure what you want to happen in case the Inventory.objectToBeFound != 1, but at the very least you need to be the Destory() below your second if statement to get this code to work.

avatar image Lasset · Feb 19, 2013 at 08:17 PM 0
Share

I didn't know about the potential answers, sorry.

I have removed the Destroy() from line 21, as you recommended. Related to the Inventory.objectToBeFound != 1, if the object clicked is not object number 1 but 2 or 3 (other objects inside the array) I want a display message again which says "Object incorrect".

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

9 People are following this question.

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

Related Questions

Text popup onMouseDown 2 Answers

OnGui Function help 1 Answer

Draw movetool gizmo in OnDrawGizmos() 1 Answer

My OnGUI() Won't show the Button elements :( 0 Answers

Drawing a GUI.DrawTexture call above GUI.Button in seperate scripts 0 Answers


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