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 Eowyn27 · Jan 15, 2014 at 06:40 PM · objectfindonmousedowngui.button

How do I show a gui.button after clicking on a specific object or disable gui.button until after click?

I'm having trouble implementing an onMouseDown() for a GUI.button. I want the button to show up only after the user clicks on Block1. Currently, the button is being shown on all views that contain Block1 or have Block1 as active.

Is there a way to just disable the button until Block1 is clicked on and then have the button show on from then but not when I restart the scene/go back to the previous script where block1 is not clicked on yet (even though block1 is active in that scene)?

So far I have something like this:

 public bool showButton = false;
 
  void onMouseDown() {
     
     if(Input.GetMouseButtonDown(0)) 
     
     showButton = true; 
 
 }
 
     void OnGUI () {
     
        
     
         // Make a background box
         GUI.Box(new Rect(10,10,250,200), "Menu");
     
              
         if (GameObject.Find("block1") && showButton== true) {
         
             if(GUI.Button (new Rect (30,40,200,70), "Back to the block with stripes ")) { 
             
                 print ("You clicked the button!");
         
                 mainCam.transform.position= new Vector3(-.13f, 0.87f, -8);
             
                 Camera.main.orthographicSize = 0.4f; 
             
             
         
         }

The only possibility that I was thinking about logically is if I said something like GameObject.Find("Block1").onMouseDown()) for the if condition but I don't think Unity accepts those parameters? I think I'm mostly confused on how to word the logic so that I can make this work.

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 HuskyPanda213 · Jan 16, 2014 at 03:40 AM 0
Share

You could create a script that sends the message, when the block is clicked, also if needed use bools to enable UI. :)

avatar image Eowyn27 · Jan 20, 2014 at 05:10 PM 0
Share

Hi,

I was wondering, what is wrong with having the On$$anonymous$$ouseDown void on the same GameObject as you have the GUI void?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KaTsuoo1 · Jan 16, 2014 at 06:17 AM

You would need a way for the game to know that you have clicked the block, which you could use a boolean variable for. So at the top of the script where you would create your variables, you could put:

var Block1Clicked : boolean = false;

Then you would change the first if statement to:

if (GameObject.Find("Block1") && Block1Clicked == true) {

Then all you have to do is to enable that variable when you have clicked on Block1, with the following line:

Block1Clicked = true;

Comment
Add comment · Show 7 · 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 Eowyn27 · Jan 16, 2014 at 02:58 PM 0
Share

I guess my main question is how do I get on$$anonymous$$ouseDown to work within onGUI? Do I just call on$$anonymous$$ouseDown outside of onGUI? How do I get on$$anonymous$$ouseDown to work with gui.button?

avatar image Eowyn27 · Jan 16, 2014 at 03:43 PM 0
Share

I edited my code to show my alterations. Even with a boolean, it doesn't work the way I want it too. With the bool, the button is disabled all the time and does not activate on$$anonymous$$ouseDown. I'm not sure why...

avatar image HuskyPanda213 · Jan 16, 2014 at 04:36 PM 0
Share

It should be On$$anonymous$$ouseDown. Ins$$anonymous$$d of on$$anonymous$$ouseDown, also your are using the same game object to make the GUI and react to clicks.

avatar image Eowyn27 · Jan 16, 2014 at 04:48 PM 0
Share

What do you mean by same game object? Hmm. I fixed the typo for On$$anonymous$$ouseDown and it still disables it all the time...

avatar image KaTsuoo1 · Jan 16, 2014 at 07:08 PM 0
Share

What HuskyPanda213 meant was that you have the On$$anonymous$$ouseDown void on the same GameObject as you have the GUI void, since it is all in the same script. However, I doubt I will be able to help you further because I don't use C#, I just knew that booleans would work the same.

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how do an action onclick an object? 3 Answers

Finding maximum peak of distance between two moving objects? 0 Answers

Object.Find distance? 1 Answer

All instance of a script and change a variable 1 Answer

How do I move the camera to another object in the scene on mouse down? 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