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 Aladine · Dec 06, 2013 at 01:51 PM · androidguibuttonclickpress

GUI.Button press (not click)

Hello everyone, I want to know if there is a possibility to make a GUI.Button return true when the user immediately press on it, not click (press and release) Am making a game for Android and it's weird to have such an effect with buttons. Am sure there is a simple solution for this, otherwise i had to make it manually

Thank you

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 robhuhn · Dec 06, 2013 at 01:56 PM 1
Share

Something like the RepeatButton? - You could lock it immediately after the first down state.

avatar image Aladine · Dec 06, 2013 at 05:09 PM 0
Share

thank you

3 Replies

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

Answer by clunk47 · Dec 06, 2013 at 04:52 PM

 using UnityEngine;
 using System.Collections;
 
 public class Example : MonoBehaviour 
 {
     bool pressed = false;
     GUIContent btn;
     int presses = 0;
 
     void Start()
     {
         btn = new GUIContent("Test");
     }
 
     void Update()
     {
         if(Input.GetMouseButtonUp (0))
             pressed = false;
     }
 
     void OnGUI()
     {
         if(GUILayout.RepeatButton(btn))
         {
             if(!pressed)
             {
                 presses++;
                 pressed = true;
             }
         }
 
         GUILayout.Label(presses.ToString ());
     }
 }
 
Comment
Add comment · Show 6 · 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 Aladine · Dec 06, 2013 at 05:11 PM 0
Share

thank you, but i about this solution and i said maybe there is an "easiest" way to do it ? i thought that just like there is a "ButtonUp" (clicked) test then there must be a ButtonDown test no ?

avatar image clunk47 · Dec 06, 2013 at 05:15 PM 1
Share

This is a very simple solution. I'm using a boolean to deter$$anonymous$$e whether or not you've pressed down on the button... This is about the easiest way I can think to do this. You press down, presses is added to once. Otherwise without the boolean, RepeatButton would keep adding to presses as you hold down the button. $$anonymous$$eep in $$anonymous$$d the int presses in this example is just that, example.

avatar image Aladine · Dec 06, 2013 at 05:19 PM 1
Share

Yes i know that this is very simple, as you said it must be the simplest manual way to do it, i just assumed that there must be a build-in function to do that, anyway, i would make this correct answer if you used touch input ins$$anonymous$$d of mouse left click... kidding :p thanx a lot man ^^

avatar image clunk47 · Dec 06, 2013 at 05:22 PM 1
Share

LOL! Hey since you mention it, just in case you didn't know, the mouse class works like touch on $$anonymous$$obile ;)

avatar image clunk47 · Dec 06, 2013 at 06:16 PM 2
Share

You're very welcome. I believe the mouse commands work, but functions won't, like void On$$anonymous$$ouseDown() won't work as touch, but in Update like in the example above,

 if(Input.Get$$anonymous$$ouseButtonDown(0)) 

Would act like

 if(Input.touchCount > 0 && Input.GetTouch (0).phase.Equals(TouchPhase.Began))
Show more comments
avatar image
3

Answer by begem0t · Aug 23, 2014 at 04:35 PM

Use GUI.RepeatButton:

  if(GUI.RepeatButton(new Rect(0,0,50,20),"Repeat")){
     ...}


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 Ramesh · Apr 19, 2020 at 03:41 AM 0
Share

This works

avatar image
2

Answer by elblogdelbeto · May 29, 2018 at 09:59 AM

there is an easy way: in the inspector of the button, add component - > event trigger and then you can add there -> add new event type and you cand find the pointer down event

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

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

Related Questions

gui.button down 2 Answers

Android Button Screen 1 Answer

android and ios - phantom UGUI Button click when loading new scene w/ finger already down 1 Answer

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

banner ad over a button, AdMob plugin problem 2 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