Search Unity

Question Check if android or iOS or PC in WebGL

Discussion in 'Scripting' started by saifshk17, Mar 29, 2023.

  1. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    488
    I have a code to check if the device is a mobile or not in my WebGL application. I want to improve this code to detect if the mobile is iOS or Android. How can I do this?

    Plugin.jslib

    Code (CSharp):
    1.  var MyPlugin = {
    2.      IsMobile: function()
    3.      {
    4.          return UnityLoader.SystemInfo.mobile;
    5.      }
    6. };
    7. mergeInto(LibraryManager.library, MyPlugin);
    Unity:

    Code (CSharp):
    1.      [DllImport("__Internal")]
    2.      private static extern bool IsMobile();
    3.      public bool isMobile()
    4.      {
    5.          #if !UNITY_EDITOR && UNITY_WEBGL
    6.              return IsMobile();
    7.          #endif
    8.          return false;
    9.      }
     
    tantx likes this.