So I am creating a unity webgl game. I want my script to know at runtime if the webgl game in the browser is on Desktop or A mobile device so I used the following method:
-I created a file named “MyPlugin.jslib” in Assets/Plugins/webgl/MyPlugin.jslib
that isn what i wrote inside this file:
var MyPlugin = {
IsMobile: function()
{
return Module.SystemInfo.mobile;
}
};
mergeInto(LibraryManager.library, MyPlugin);
-Then I added following to my unity script:
using System.Runtime.InteropServices;
#region WebGL is on mobile check
[DllImport(“__Internal”)]
private static extern bool IsMobile();
public bool isMobile()
{
#if !UNITY_EDITOR && UNITY_WEBGL
return IsMobile();
#endif
return false;
}
#endregion
I used bool isMobile() to Check if the device on which my webgl game is running is a mobile device or not. Everything worked fun in editor. But when I sarted to build the game. The build failed and these errors showed:
'Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js: undefined symbol: IsMobile (referenced by top-level compiled C/C++ code)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun ()’
'Building Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js failed with output:
error: undefined symbol: IsMobile (referenced by top-level compiled C/C++ code)
warning: Link with -s LLD_REPORT_UNDEFINED to get more information on undefined symbols
warning: To disable errors for undefined symbols use -s ERROR_ON_UNDEFINED_SYMBOLS=0
warning: _IsMobile may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
emcc2: error: ‘“C:/Software/unity 2021 new/2021.3.11f1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/node/node.exe” “C:\Software\unity 2021 new\2021.3.11f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\src\compiler.js” C:\Users\Hp\AppData\Local\Temp\tmpjf_g3fkj.txt’ failed (1)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun ()
’
Please help resolve this and if there is some other way from which I can check device type then that will work too. Thanks