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
5
Question by TheRedRabbit · Nov 29, 2014 at 04:19 PM · c#4.6gui button

[4.6] GUI Button OnRelease?

Hey community,

in my current Android app made in Unity 4.6 I use the new Gui System. The new Button has its On Click() event which is working fine. But if the player is releasing the button the main charakter just walks endless further.

I tried to use the WaitForSecounds() methode to reset the button in a way, but it isnt working. This is my code so far:

 using UnityEngine;
 using System.Collections;
 
 public class UIcontroller : MonoBehaviour 
 {
     public bool pressedD = false;
     public bool pressedU = false;
 
     
     IEnumerator Wait(){
         yield return new WaitForSeconds (3.0f);
     }
 
     public void ButtonDOWNpresser() //Called from the OnClick() section of the GUI button
     {
         pressed1 = true;
         StartCoroutine(Wait());
         pressed1 = false;
 
     }
 
     public void ButtonUPpresser()
     {
         pressedU = true;
             StartCoroutine(Wait());
         pressedU = false;
     }
 }

Is there no On Release() section to the On Click() section for the GUI button?

Thank you very much for your help!

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

1 Reply

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

Answer by Kiwasi · Nov 29, 2014 at 07:58 PM

Add an Event Trigger component to your button (In the event menu). From there you can add a listener for OnPointerUp. Treat it just the same as OnClick.

Note: It actually sounds like you want an OnPointerDown instead of OnClick. A click is defined as a button going down and then being released on the same element. So typically OnClick and OnPointerUp will be called in the same frame.

Comment
Add comment · Show 4 · 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 TheRedRabbit · Nov 29, 2014 at 08:10 PM 0
Share

I see. Everything works fine now. Thank you very much

avatar image Frazeke · Feb 05, 2015 at 07:00 AM 0
Share

Been trying to figure out a way around having it only running my code on release! Thank you for saving me a few more hours of heartache! Event Trigger has saved my life!

avatar image Pitch92 · Jun 30, 2018 at 03:25 PM 0
Share

why would there be such complex tutorials on the internet if it's that easy... thank you very much ! :)

avatar image SalvoSoftware · Jun 10, 2020 at 10:13 AM 0
Share

I know this is an old question, but this method only works with $$anonymous$$ouse or Touch (in this case), if you're using Keyboard or Gamepad can you achieve the same "Down"/"Up" functionality?

Thanks!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Making a bubble level (not a game but work tool) 1 Answer

Weird NullReferenceException 1 Answer

An OS design issue: File types associated with their appropriate programs 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