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 PaxForce · Aug 07, 2014 at 06:24 AM · guigui.button

GUI.Button with double functionality

  1. I want to have a GUI button on my top right.

  2. When I mouseClick it ONCE, I want it to go to MainMenu screen (still inside the app)

  3. When I mouseClick and hold down the LMB for 2 seconds, I want the game to load the login screen, which is outside the app itself

I've been trying to work this out for the whole damn day yesterday and the day before, so I'm pretty mad and desperate. Pls help me out with this.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Andres-Fernandez · Aug 07, 2014 at 06:43 AM

According to the docs, GUi.Button is a single press button, so it returns true whenever it is pressed (I haven't tried it, but it seems it only returns true the frame the mouse clicks down on it). I suggest you use some kind of timer and control it with the OnMouseUp() function.

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 PaxForce · Aug 07, 2014 at 06:57 AM 0
Share

I'm a newb, bro ... I really need somebody to code it out for me :(...I was trying to solve it yesterday but I just can't anymore.

avatar image RedDevil · Aug 07, 2014 at 07:00 AM 0
Share

he chould place thi on a empty game object and give it a dont destroy on load and it will keep the object http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

avatar image
0

Answer by robertbu · Aug 07, 2014 at 07:06 AM

Try this:

 #pragma strict
 
 public var waittime : float = 2.0;
 private var timestamp : float = 0.0;
 
 var rect : Rect = Rect(100,100,200,50);
 
 function OnGUI() {
     var e : Event = Event.current;
     
     if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition)) {
         timestamp = Time.time;
     }
     
     if (GUI.Button(rect, "Some Button")) {
         if (Time.time - timestamp > waittime) {
              Debug.Log("Clicked and held");
         }
         else {
             Debug.Log("Just clicked");
         }
     }
 }
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 PaxForce · Aug 07, 2014 at 09:04 AM 0
Share

this is UnityScript, right? :) I'm learning C# but I think I will be able to "translate" this into C#. I'm gonna go learn something about Events now and then I'll get back to you and accept your answer if it solves my problem. Until then...

avatar image robertbu · Aug 07, 2014 at 02:13 PM 0
Share

A C# translation:

 using UnityEngine;
 
 public class Bug25a : $$anonymous$$onoBehaviour
 {
     public float waittime = 2.0f;
 
     private float timestamp = 0.0f;
     private Rect rect = new Rect(100,100,200,50);
     
     void OnGUI() {
         Event e = Event.current;
         
         if (e.type == EventType.$$anonymous$$ouseDown && rect.Contains(e.mousePosition)) {
             timestamp = Time.time;
         }
         
         if (GUI.Button(rect, "Some Button")) {
             if (Time.time - timestamp > waittime) {
                 Debug.Log("Clicked and held");
             }
             else {
                 Debug.Log("Just clicked");
             }
         }
     }
 }

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

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

Related Questions

button with content in multiple colors 3 Answers

(Unity 4.6) Button animations 1 Answer

Simulate IMGUI button press 1 Answer

Unity GUI Nested If statements causing GUI Buttons not to render 1 Answer

GUI.Button doesn't show texture 0 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