- Home /
Detect mobile client in webgl
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?
Answer by TOES · Feb 11, 2020 at 05:01 PM
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;
}
@TOES I'm using exactly this solution, I attached the script to a empty game object. The game runs in the editor, but when I publish it to the browser I get this error:
Any ideas?
Maybe this could help: Try to replace "UnityLoader.SystemInfo.mobile;" To "Module.SystemInfo.mobile"
Answer by Brodus · Feb 01 at 04:35 AM
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?
In your Unity project folder, you should have an "Assets/plugins" directory.
The "WebGL" folder is one you can create yourself, and "MyPlugin.jslib" is a regular text file, but with a .jslib extension (instead of .txt, or *.cs).
Your answer

Follow this Question
Related Questions
Failure to compile c++ for WebGL 1 Answer
C# WebGL open email client Win32 exception 2 Answers
Can i catch the WebGL Memory size error? 1 Answer
As I avoid downloading a webgl content made with unity. 0 Answers
Problems with webgl 1 Answer