1
\$\begingroup\$

When I build a game using Unity 2017.2.0f3 and the Cardboard SDK (using XR settings) and run it on my device, I see two controls overlaid on the screen, a cross and a gear:

enter image description here

Currently, pressing the cross control does nothing. I'd like to make the cross exit VR mode when pressed.

\$\endgroup\$
3
+50
\$\begingroup\$

When clicking ✕ (close), your Unity app should get an escape key press notification & you should be able to handle it the same way as an actual key down event. For example, to quit, you would do this:

void Update(){
  if(Input.GetKeyDown(KeyCode.Escape)){
    // close icon pressed, place appropriate code here
    Application.Quit();
  }
}

There was an error that prevented this; make sure Unity & your various SDKs are patched & up to date.

\$\endgroup\$
  • \$\begingroup\$ Someone anonymously edited attempted to edit this answer with the statement "it is not work, I think it maybe block be due to Cardboard SDK." If you run into a problem with the answer, leave some feedback (as a comment, not an edit) describing the situation. \$\endgroup\$ – Pikalek Feb 28 at 14:45
0
\$\begingroup\$

It looks like a simple UI. I suppose you need to find right Canvas in the Unity3d Editor window and add OnClickEvent to these elements (cross and settings icons). If cross is containing button component you will simply need to add OnClickEvent that will escape VR mode.

\$\endgroup\$
  • \$\begingroup\$ this canvas generated by Unity. How can I have access to it? \$\endgroup\$ – GuardFromUA Mar 1 '18 at 13:11
  • \$\begingroup\$ You need to find this Canvas in Unity3d Hierarchy window. If you see these elements in Editor window mode (Scene) just click on them and they will be selected in hierarchy window. \$\endgroup\$ – Bogdan Mar 1 '18 at 13:44
  • \$\begingroup\$ I can't view it in Unity3d Hierarchy window. It is generated by Unity automatically on mobile device. What I need is some access to Unity automatically generated UI(VR UI, in this case). \$\endgroup\$ – GuardFromUA Mar 1 '18 at 13:54
  • \$\begingroup\$ @GuardFromUA it's probably an old gui system. You should find the code that displays those. I'm not familiar with old system but as far as my experience goes it's created via code. \$\endgroup\$ – Candid Moon _Max_ Mar 1 '18 at 14:03
  • \$\begingroup\$ @CandidMoon I searched and can't find it... \$\endgroup\$ – GuardFromUA Mar 1 '18 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.