gigacee / CheckIfMobileForUnityWebGL

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

License:MIT License


Languages

Language:C# 67.9%Language:JavaScript 32.1%