I am using Unity5 and the Gvr.I am trying to implement a menu where the user stares at a button for a 5secs then the button is to be enabled.Can anybody please help me? I have implemented the reticle and it detects the button.I am not sure how and where I should add the time trigger.
Asked
Active
Viewed 2,642 times
1
-
Post the current code you have. Maybe someone can figure out what you need to do next. – Programmer Jul 11 '16 at 13:13
2 Answers
0
Attach this script to your button object:
[RequireComponent(typeof(Button))]
public class InteractiveItem : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public Image progressImage; // add an image as child to your button object and set its image type to Filled. Assign it to this field in inspector.
public bool isEntered = false;
RectTransform rt;
Button _button;
float timeElapsed;
Image cursor;
// Use this for initialization
void Awake ()
{
_button = GetComponent<Button>();
rt = GetComponent<RectTransform>();
}
float GazeActivationTime = 3;
void Update ()
{
if(isEntered)
{
timeElapsed += Time.deltaTime;
progressImage.fillAmount = Mathf.Clamp(timeElapsed/GazeActivationTime,0,1);
if(timeElapsed >= GazeActivationTime)
{
timeElapsed = 0;
_button.onClick.Invoke();
progressImage.fillAmount = 0;
isEntered = false;
}
}
else
{
timeElapsed = 0;
}
}
#region IPointerEnterHandler implementation
public void OnPointerEnter (PointerEventData eventData)
{
isEntered = true;
}
#endregion
#region IPointerExitHandler implementation
public void OnPointerExit (PointerEventData eventData)
{
isEntered = false;
progressImage.fillAmount = 0;
}
#endregion

Umair M
- 10,298
- 6
- 42
- 74
-
:Thank you :).If its not too much trouble,I am using the Gvr gaze on the Ui button. ie,the reticle on the button.So the cursor would be the reticle in my case.How can i modify ? I get the eroor stating "typename or namespace image could not be found". And thank you , not everybody replies with code :) – Saranya Ananthakrishnan Jul 12 '16 at 16:00
-
At start of script add `using UnityEngine.UI;`. And if your GVR gaze works fine, attaching this script to button should handle events like `OnPointerEnter `, `OnPointerExit` etc. let me know if there is anyother problem. Please mark the answer correct and vote up :) – Umair M Jul 13 '16 at 09:28
-
I'm trying to use the same script but it is not working anymore :( https://stackoverflow.com/questions/60114336/onpointerenter-is-not-being-called – Feb 07 '20 at 13:41
0
Write a script that implements IGvrGazeResponder
and at here, you have to override OnGazeTrigger()
function and in that you can write:
StartCoroutine(YourControllerScript.control.LoadLevel(sceneToLoad))
to load the scene that you want

ρяσѕρєя K
- 132,198
- 53
- 198
- 213
-
Can you explain with some sample code ...just an outline..I'm not familiar with co routines.Thanks – Saranya Ananthakrishnan Oct 08 '16 at 09:44
-
Coroutine is a good functionality to load a scene as using it you stop a frame or scene for given time Can you send me your code and related prob on lokesh_goyal2011@yahoo.com – Luv Fight Fight Oct 12 '16 at 07:16