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 Drew 2 · Mar 17, 2011 at 04:07 PM · guimouseclickdrag-and-dropgui-button

Buttons that remove themselves when clicked mess up other gui elements

Basically, I'm trying to make buttons within a panel which, when clicked, create an object which can be dragged and dropped into the world. The button should remove itself from the panel when clicked. Doing this has caused some pretty strange behavior, though:

if (!pickUpFlag && GUI.RepeatButton(new Rect(70,25, 50, 50), "Magic"))
{
    pickUpFlag = true;
}
if (!endFlag && GUI.RepeatButton(new Rect(10,85, 50, 50), "End"))
{
    endFlag = true;
}
if (!startFlag && GUI.RepeatButton(new Rect(10,25, 50, 50), "Start"))
{
    startFlag = true;
}

The above code functions weirdly... clicking either of the first two buttons works fine, however, clicking the last button IN CODE (the start button) causes some issues; Buttons will no longer highlight, and in some circumstances (that I can't replicate) the gui will show one of the other buttons as active/clicked when it is moused over. Additionally, anything in other parts of the code which is supposed to execute on !Input.GetMouseButton(0) won't execute until the mouse button is clicked again. Weird stuff. Any ideas?

NOTE: I am using RepeatButton because you're supposed to drag the item off of the button and release it into the world... a regular Button doesn't return true until I release the mouse button (while mouse is stull on top of it), but RepeatButton returns true as soon as it is pressed. The way it works in my program is: The user presses the mouse button over one of these buttons. When the mouse button is depressed, the button disappears and a graphic/model appears attached to the mouse. That can be dragged and dropped into the world. Regular buttons won't work because they don't return true until I release the mousebutton.

Comment
Add comment · Show 1
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 Uzquiano · Mar 17, 2011 at 05:09 PM 0
Share

Excuse me, but why do you use RepeatButton? Have you tried to put two nested if conditions ins$$anonymous$$d of joining the two conditions in one if?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DaveA · Mar 17, 2011 at 05:11 PM

Do these need to be RepeatButtons? Those are for 'continuous events' like holding a key down. But your code implies that these are single-use, as clicking one will turn it off. I assume all those vars are set to false initially. Try using just Button instead, see if that helps.

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 Drew 2 · Mar 17, 2011 at 05:46 PM 0
Share

using repeatbutton because you're supposed to drag the item off of the button and release it into the world... a regular button doesn't return true until I release the mouse button, but RepeatButton returns true as soon as it is pressed. I will update the question.

avatar image DaveA · Mar 17, 2011 at 10:26 PM 0
Share

In which case I'd try using Update to do the drag. Get mouse position, check against the rect of the button, move to follow mouse.

avatar image
0

Answer by MithosAnnar · Feb 12, 2012 at 01:19 PM

If you want to make the button disappear use this script:

 var bool : boolean = false;
 
 if ( bool == false) {
 
 if ( GUI.Button( Rect(70, 25, 50, 50), "Something")) {
 
     bool = true;
 
 }
 
 }
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

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

2 People are following this question.

avatar image avatar image

Related Questions

Change button texture when its clicked 1 Answer

Why can't i click a button when in first person? 2 Answers

GUI based character control 2 Answers

Can I change GUIButton behaviour? 1 Answer

Move the text in a GUI Button/Box 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