I need to detect whether the user is running a webgl app in a mobile browser or on a desktop/laptop browser. Is this possible to detect using the Unity API, or you need to do some HTML hack?
1 Like
Found the answer. In case anyone else needs it:
in assets/plugins/webgl/MyPlugin.jslib
var MyPlugin = {
IsMobile: function()
{
return UnityLoader.SystemInfo.mobile;
}
};
mergeInto(LibraryManager.library, MyPlugin);
Then from unity:
[DllImport("__Internal")]
private static extern bool IsMobile();
public bool isMobile()
{
#if !UNITY_EDITOR && UNITY_WEBGL
return IsMobile();
#endif
return false;
}
Tested with Unity 2022.3:
bool isWebGLOnDesktop = !Application.isMobilePlatform
&& Application.platform == RuntimePlatform.WebGLPlayer;
bool isWebGLOnMobile = Application.isMobilePlatform
&& Application.platform == RuntimePlatform.WebGLPlayer;
Using Unity 2021.2.9f1 and I don’t see ‘assets/plugins/webgl/MyPlugin.jslib’ am I missing something? Can someone direct me toward the location? Or, is there a 2021 equivalent?
Hi, @TOES , can we know with this method if we are on iphone or ipad in addition ? Thank you
(i need to know if i am on ipad or iphone to play video without sound )