LoginSignup
16
11

More than 5 years have passed since last update.

【Unity】【WebGL】WebGLプレイヤーをブラウザ全体に表示したい

Last updated at Posted at 2018-05-22

環境

Unity2017.4.3f1
Chrome(66.0.3359.181)

やりたいこと

ss1.png

↑これを

↓こうしたい

ss2.png

index.htmlとstyle.cssを変更する

index.html中のgameContainerからstyleを削除する

<!-- <div id="gameContainer" style="width: 960px; height: 600px"></div> -->
<div id="gameContainer"></div>

TemplateData/style.cssに以下の2行を加える

html,body,div { margin: 0; padding: 0; width: 100%; height: 100%;}
canvas { margin: 0 0 0 0; position: absolute; z-index: 9; width: 100%; height: 100%;}

以上。

ビルドするごとに毎回変更するの?

UnityのWebGLテンプレート機能を使えば、毎回手直しする必要は無い

今回の例なら、以下の2つのファイルを置いておけば良い

  • Assets/WebGLTemplates/{TEMPLATE_NAME}/index.html
  • Assets/WebGLTemplates/{TEMPLATE_NAME}/TemplateData/style.css

WebGLのPlayerSettingsのテンプレート選択項目に新しいテンプレートが追加されるので、それを選択してビルドする

ss3.png

16
11
0

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
16
11