问题
I have modified the Google Cardboard DemoScene with my own UI text buttons. By default, these buttons respond to Onclick() or tap events to trigger actions. I would like to trigger these actions when the user sets their gaze on the object for 2 seconds.
I suspect I need to add some kind of conditional statement in the GazeInputModule but I can't figure out how to measure the time. Can anyone point me in the right direction? Is this the right approach or should I try something else? This is all still pretty new to me so even basic tips are very helpful!
回答1:
Here's how I enabled a button click on a timed gaze. In my case I created a button to load the next scene.
I created a scene in my Unity game, so I didn't start off with modifying the Google Cardboard DemoScene, but the principles are similar.
Create a script named "LoadSceneButton.cs" (or whatever suitable name such as "TimedGazeButton.cs" and attach it to the button you want to enable the timed gaze on. See sample script http://pastebin.com/CXd6HA3C
On the button, add the "Event Trigger" component and set triggers - see screenshot Timed gaze button Event Triggers
Pointer Enter
to the button'sLoadSceneButton.SetGazedAt
, and check the box to pass in theTRUE
value. This indicates that user has started gazing at the object.Pointer Exit
to the button'sLoadSceneButton.SetGazedAt
, and uncheck the box to pass in theFALSE
value. This indicates that user has stopped gazing at the object and has moved the reticle somewhere else.
The "LoadSceneButton.cs" will start timing the gaze when user's reticle moves into the button. Once the gaze time has reached a particular duration, the button's
OnClick
event is invoked. If the user moves the reticle away before that time, the timer is reset.
The version of Unity I used was Google Daydream Technical Preview v5.4.2f2-GVR12 dated 10th November 2016, with Google GVR SDK 1.0.3.
来源:https://stackoverflow.com/questions/34384382/use-gaze-input-duration-to-select-ui-text-in-google-cardboard