Unity5 WebGL gyroscope access

Hello everybody,

I want to make a WebGL demo for Google Cardboard with Unity5.

Is there a way to access the gyroscope from a Unity5 WebGL Application running in Android or IOS browser? It works fine as Android Application, but I want to access it from a Android device via the web browser and without a Plugin.

Alternatively I consider to use an external javascript library and transfer the sensordata to Unity. In the web player I used Application.ExternalCall to call a javascript function and unity.SendMessage() to send a message from javascript to Unity. How can I send messages from a Unity WebGL Application to the embedding Website and vice versa?

Hints or sample code would be great!

many thanks, klap

Mobile browsers and devices are currently not supported by our WebGL export.

Afaik you can’t get the gyroscope from WebGL atm.

For script interaction see the manual at Unity - Manual: Interaction with browser scripting

You can get through javascript interop as shown in sama-van’s answer here:

https://forum.unity.com/threads/can-webgl-access-mobile-sensors.332566/