Skip to content

The plugin to check if your Unity WebGL game is running on a PC or mobile device.

License

Notifications You must be signed in to change notification settings

gigacee/CheckIfMobileForUnityWebGL

Repository files navigation

Check if Mobile for Unity WebGL

The plugin allows you to check if your Unity WebGL game is running on a PC or mobile device.

on PC on Mobile

日本語による説明 / Explanation in Japanese

Unity WebGL の実行環境が PC かモバイル端末かを判別するスクリプトを公開しました

Usage

This script uses .jslib plugin. You can check if your Unity WebGL game is running on a PC or mobile device by calling IsMobile() in CheckIfMobileForUnityWebGL.jslib as follows:

#if !UNITY_EDITOR && UNITY_WEBGL
    [System.Runtime.InteropServices.DllImport("__Internal")]
    private static extern bool IsMobile();
#endif

    private void CheckIfMobile()
    {
        var isMobile = false;

#if !UNITY_EDITOR && UNITY_WEBGL
        isMobile = IsMobile();
#endif

        GetComponent<Text>().text = isMobile ? "Mobile" : "PC";
    }

Installation

Package Manager

https://github.com/gigacee/CheckIfMobileForUnityWebGL.git?path=Assets/Plugins/CheckIfMobileForUnityWebGL

Manual

Copy Assets/Plugins/CheckIfMobileForUnityWebGL/CheckIfMobileForUnityWebGL.jslib to your project.

⚠️ Be sure to put it in Assets/Plugins/ .

About

The plugin to check if your Unity WebGL game is running on a PC or mobile device.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published