3
3

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覚書 テクスチャのサイズにオブジェクトを合せる(UI)

Last updated at Posted at 2018-11-06

UIに関する質問より。

テクスチャのサイズにオブジェクトを合せる(UI)

「画像のサイズが正方形ではない場合、テクスチャの縦横のサイズがImageオブジェクトの縦横のサイズとなるように張り付ける簡単な方法があるかどうか。」

ライフゲージのような、デザインされた部品の一部をゲームの進行状況に応じて色を変える場合など、部品の一部だけを画像ファイルにして重ねたい場合があります。

Assetsに、UIで使用する画像ファイルをドラッグ&ドロップで追加

Texture Typeを変更

Assetsに追加した画像ファイルをクリックし、InspectorパネルでTexture TypeをSprite(2D and UI)にし、Applyする。
(UIの部品に張り付けるため)
image.png

Create→UI→ImageでImageを追加する

image.png

ImageのInspectorのSource Imageのところに、Assetsの中にある画像をドラッグ&ドロップで設定する。

image.png

InspectorパネルのAdd Componentから、Content Size Fitterを追加する。

Content Size Fitter(Script)パネルで、Horizontal FitとVertical Fitを「Preferred Size」に変更する

image.png

画像サイズと同じサイズに変更される

Rect TransformのWidthとHeightが画像サイズと一致している
image.png

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?