- Home /
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
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 :)
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.
I try this all day but, Pointer Enter is just when you put cursor on button .. no click .. and there is no wait :)
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());
}
I will try tomorrow, but is rectangle good solution ? if i will have 50 buttons ?
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)
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.
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
Follow this Question
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