Hello.
I am working on an application for Hololens in which I wish to enable a child of a game object through focusing my gaze on it, and then keep it active by gazing either on the parent, or on the child itself. It should disable itself once the parent or the child are no longer in focus. Like a pop up menu.
Currently, I am using a boolean in a script attached to the parent, and two functions which can enable/disable the boolean. I call these functions in a script attached to the child. The boolean tells the parent if the child is in focus. If the parent and the child are not in focus, the child gets disabled.
Here is an example of how it works:
Parent class:
public class Parent : MonoBehaviour, IFocusable
{
private bool childFocused = false;
public void OnFocusEnter()
{
ActivateChild();
}
public void OnFocusExit()
{
if (childFocused == false)
{
DeactivateChild();
}
public void TurnOnFocus()
{
childFocused = true;
}
public void TurnOffFocus()
{
childFocused = false;
}
}
Child class:
public class Child : MonoBehaviour, IFocusable
{
public void OnFocusEnter()
{
ActivateChild();
gameObject.GetComponent().TurnOnFocus();
}
public void OnFocusExit()
{
gameObject.GetComponent().TurnOffFocus();
}
}
It is not working properly though. Sometimes the child stays active indefinitely, other times it closes immediately.
Any ideas or suggestions to what might be wrong would be greatly appreciated. Thank you in advance.