2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unity WebGLでビルドするとHTMLのInputでキーボード入力ができない問題

Last updated at Posted at 2019-02-19

はじめに

こんにちは、のんびりエンジニアのたっつーです。
ブログに書いた内容のメモになります。

Unity で WebGL を出力するとブラウザで実行可能な出力が可能になります。
上記のWebGL は HTML5 の Canvas 要素で実装されているのですが、このHTML内に以下のようなテキスト入力欄を同時に表示すると、ここの入力ができなくなる問題があるようです。

<input type="text" name="name" size="30">

WS000000-5.jpg

ソースコード

「WebGLInput.captureAllKeyboardInput = false」にする事により、HTML内でのキーボード入力が可能となるようです。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HtmlInputControl : MonoBehaviour
{
    void Start()
    {
# if !UNITY_EDITOR && UNITY_WEBGL
        WebGLInput.captureAllKeyboardInput = false;
# endif
    }
}

デモ

終わりに

よければ ブログ「初心者向けUnity情報サイト」の方にも色々記載しているのでぜひご参照いただければと思います。

2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?