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
1
Question by Mirko · Feb 23, 2011 at 04:17 PM · onmousedowngui.button

Mouse down on GUIButton

How do I make something happen when I click a GUIButon but not on mouse release.

If I use this code:

if ((GUI.Button(Rect(800,100,110,110),btnTexture)))

it reacts when I release it :(

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Joshua · Feb 23, 2011 at 04:23 PM

OnMouseDown OnMouseUp

I think if you make it work on function OnMouseDown () it should work :)

So don't put it in your function Update or whatever, make a seperate function:

function OnMouseDown(){ dowhatyouwantittodo; }

Comment
Add comment · Show 1 · 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 Bill 2 · Oct 29, 2011 at 12:08 PM 0
Share

but you can't draw gui buttons in an On$$anonymous$$ouseDown function can you?

avatar image
1

Answer by TheDemiurge · Feb 23, 2011 at 04:46 PM

If you need action while the mouse is down, you can use GUI.RepeatButton(..) for it. If you want just one onmousedown, you can either add some manual checks or use a RepeatButton with a flag for being held down. Keep in mind, you should not be processing more than the bare minimum of code inside OnGUI() since this can get called several times per frame.

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
1

Answer by Bill 2 · Oct 29, 2011 at 12:51 PM

private var leftMouseClicked : boolean = false;

function OnGUI() {

     //used for on mousedown hack
 
     ix = Input.mousePosition.x; 
 
     iy = Input.mousePosition.y; 
 
     var transMouse = GUI.matrix.inverse.MultiplyPoint3x4(Vector3(ix, Screen.height - iy, 1));
 
     var closeButRect=Rect ((Screen.width/2) + 135,Screen.height - 470,14,14);
     
     GUI.Button(closeButRect,"", "closeBtn");
     
     
     if (leftMouseClicked){
 
         if(closeButRect.Contains(Vector2(transMouse.x,transMouse.y))){
 
             //mouse down on but - do something


             leftMouseClicked=false;
             
             
         }
         
     }

}

//hack to get close buttons to respond on mouse down

function Update(){

 if(Input.GetMouseButtonDown(0)){


     leftMouseClicked=true;

 }else{

     leftMouseClicked=false;

 }


}

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

1 Person is following this question.

avatar image

Related Questions

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

Centering a texture in a GUI.Button 4 Answers

move a button On click - rather than on game start 1 Answer

Accessing a particular GUI.Button in code after it has been created 1 Answer

Creating my own DrawButton method but am stuck 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