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 HolBol · Jan 14, 2013 at 08:31 PM · androidguibuttongetbutton

Alternative to GetButtonUp for GUI.Button

I need a system where I click an hold a GUI button, something charges, and when i let go of the button, do something else? There doesn't seem to be a simple piece of code in the reference for such a basic problem. It's ridiculous. If you can get ButtonDown and ButtonUp for physical keys, why not for the GUI?

A hint, this is for android.

Comment
Add comment · Show 3
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 HolBol · Jan 15, 2013 at 08:44 AM 0
Share

Anybody? I really need this answered.

avatar image FLASHDENMARK · Jan 15, 2013 at 09:50 AM 0
Share

Would GUI.RepeatButton be of some help?

http://docs.unity3d.com/Documentation/ScriptReference/GUI.RepeatButton.html

avatar image HolBol · Jan 15, 2013 at 10:25 AM 0
Share

See response to mike

1 Reply

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

Answer by whydoidoit · Jan 15, 2013 at 09:49 AM

How about this?

    var buttonDown : boolean;

    function OnGUI()
    {
           if(GUILayout.Button("Press Me"))
           {
               buttonDown = true;
               DoSomething();
           }
           else if(buttonDown)
           {
                buttonDown = false;
                DoSomethingElse();
           }
    }
Comment
Add comment · Show 8 · 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 HolBol · Jan 15, 2013 at 10:25 AM 0
Share

Unfortunately not. I need a value to increase over time while the buttons is held down, and be able to be released at any point.

avatar image whydoidoit · Jan 15, 2013 at 10:29 AM 0
Share

Isn't that just

  if(GUILayout.RepeatButton("Press $$anonymous$$e"))
  {
        someValue++;
        buttonDown = true;
  }
  else if(buttonDown)...
avatar image HolBol · Jan 15, 2013 at 10:39 AM 0
Share

But repeat button would increment it, and once the bool is true, apply the number. I need it to only apply once it has been let go.

avatar image whydoidoit · Jan 15, 2013 at 11:16 AM 0
Share

But that's why I had the else if (buttonDown) you would only apply it then...

avatar image whydoidoit · Jan 15, 2013 at 11:38 AM 1
Share

So you're right, you have to check the up event only on repaint - this does the Debug.Log only when the button is released.

 using UnityEngine;
 using System.Collections;
 
 public class TestButton : $$anonymous$$onoBehaviour {
     
     int powerUp;
     bool buttonDown;
     
     void OnGUI()
     {
         if(GUILayout.RepeatButton("Hello"))
         {
             
             powerUp++;
             buttonDown = true;
         }
         else if(buttonDown && Event.current.type == EventType.repaint)
         {
             buttonDown = false;
             Debug.Log(powerUp.ToString());
         }
     }
 }
 
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

11 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

Related Questions

GUI Button for Android 1 Answer

Android Button Screen 1 Answer

banner ad over a button, AdMob plugin problem 2 Answers

Why i cant press(use) joystick and gui button at the same time ???? 1 Answer

Switching a GUIbuttons texture when holding your finger on it? 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