Stare and Click Buttons

Hi!

I’m a 3D designer, recently I have downloaded Unity to see if I can do a virtual reality app, so far I have managed everything pretty well, but I need one of those “stare and click” buttons and I have absolutely no idea on how to do it. I searched this forum and google but I couldnt find anything usefull, can anyone give me an idea on how
can I do this?

Basically what I need is:

Looking at an icon located in space ex:(box) and after 3 seconds of looking at it perform an action, in this case I would be switching the texture on another object (I know how to do that part).

If it possible is there anyway to make it using Javascript? Is the one I understand better.

Thanks!

Here’s what I would try:

Make a script and attach it to a GameObject somewhere (just one instance of this script). In its update method you fire a ray from the camera that is the user’s main eye. Then you send a message to the first GameObject you hit with the ray:

gameObject.SendMessage(“Stare”);

Make a new script. This you attach on all game objects that should be “stareable”. Here you receive “Stare” messages and set a bool to true. Then you make a update function. If bool is true (the object is being stared) you store Time.time in a number if number equals 0, then you set the bool to false. If bool was false you set the number to zero. Now the update checks if the number is not 0 and if Time.time-number is greater than for example 2 sec. If it is it means that the GameObject has been stared at for 2 seconds. Now you send a message to the same GameObject that received the Stare message:

gameObject.SendMessage(“StareAction”);

Then you just need to attach the appropriate script on the GameObject that reacts to a StareAction message (pick up item/open door/explode item/deal damage/whatever).

Best of luck to you!

I have been able to make it work in C# using this way, it is working great now, but I have another problem, maybe you can help me I have posted it in here, thank you very much for your help, I really appreciate it!