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 Stephanides · Mar 30, 2015 at 11:08 AM · guibuttonevent triggering

Event Trigger

Hello, i want to make a hint on my menu. For example when i hold mouse on button it will show message what actuall button do. How is the best way ? Im using GUI Button and Event Trigger component

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
1
Best Answer

Answer by Stephanides · Mar 30, 2015 at 11:37 AM

yes i know that make GUI Label, i just need to know if my mouse is on button position for 3 seconds :) now im using PointerExit but i need 3 seconds later to show text :)

Comment
Add comment · Show 13 · 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 Nido · Mar 30, 2015 at 03:07 PM 0
Share

If I'm understanding, you may have a StartCoroutine(showInfo()) with a 3 seconds yield when pointing. And if you need, stop it when PointerExit.

 void pointing()
 {
   StartCoroutine(showInfoDelay());
 }
 
 IEnumerator showInfoDelay()
 {
   yield return new WaitForSeconds(3f);
   showInfo();
 }

Add a semaphore for avoid multiple calls to the coroutine.

But not sure if I'm understanding the issue X)

EDIT: call "pointing()" when pointing or cliking, up to your code.

avatar image Stephanides · Mar 30, 2015 at 06:53 PM 0
Share

I try this all day but, Pointer Enter is just when you put cursor on button .. no click .. and there is no wait :)

avatar image Nido · Mar 30, 2015 at 09:21 PM 0
Share

Sorry, I missunderstood the Pointer Enter. Hm... the problem is not trigger the coroutine, because you may start the coroutine inside the OnPointerEnter. The problem is when the mouse points out from the button before that 3 seconds. $$anonymous$$aybe you could check if the mouse still is over the button after that 3 seconds. Pseudocode (I can't test today):

 //define a rect
 rect = new Rect(x, x, x, x);
 
 void OnPointerEnter()
 {
    StartCoroutine(infoDelay())
 }
 
 IEnumerator infoDelay()
 {
    yield return new WaitForSeconds(3f);
    check$$anonymous$$ousePosition();
 }
 
 void check$$anonymous$$ousePosition()
 {
    mouse = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
  
    if(rect.Contains(mouse))
    {
       showInfo$$anonymous$$ethod(); //label, window, object....
    }
 }

Is this closer to your solution?

EDIT: add:

 void OnPointerExit()
 {
    StopCoroutine(infoDelay());
 }
avatar image Stephanides · Mar 30, 2015 at 10:08 PM 0
Share

I will try tomorrow, but is rectangle good solution ? if i will have 50 buttons ?

avatar image Nido · Mar 31, 2015 at 08:11 AM 1
Share

In your case, set true pointing in the pointer event:

 using UnityEngine;
 using System.Collections;
 
 public class Timer : $$anonymous$$onoBehaviour 
 {
     private float targetTime = 3f;
     private float timer = 0;
 
     private bool pointing = false;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () 
     {
         if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.A) && !pointing)
         {
             pointing = true;
         }
 
         if(pointing)
         {
             timer += Time.deltaTime;
         }

         if(timer >= targetTime)
         {
             pointing = false;
             timer = 0;
             Debug.Log ("show info");
         }
 
         Debug.Log (timer);
     }
 }


EDIT: after "if pointing", add else { timer = 0; } for reset the timer. And add pointing false OnPointerExit.

Hum... if this is not correct, no have more ideas, sorry haha x)

Show more comments
avatar image
0

Answer by Nido · Mar 30, 2015 at 11:26 AM

You have GUI.Tooltip, or make a GUI.Label at mouse position when pointer is over the button, if you dont need a very artistic explanation.

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 Stephanides · Mar 30, 2015 at 12:12 PM 0
Share

I have Button, and component on Button is Event Trigger, there im using Pointer Enter and this method :

 public void SetInfoText(string text)
     {
 
         Debug.Log("Ukazujem na tlacidlo");
     
     }

When i show with cursor on button debug will run, i need to do this - hold cursor 3 seconds and then will debug run

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

Clicking Trigger 1 Answer

gui text button dont work 1 Answer

How to make a or array of GUI.Button's? 1 Answer

Create 3D GUI Button? 2 Answers

Embed GUI Skin in GUI Button 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