LoginSignup
0
0

More than 5 years have passed since last update.

ImageにResourcesLoadしたSpriteをセット メモ

Last updated at Posted at 2017-02-22

いつも忘れるのでメモ

public Sprite[] textures;
textures = Resources.LoadAll<Sprite>("Chara");

参考URL:
http://nekosuko.jp/blog/?p=205#comment-27

参考URLより内容貼り付け

Sprite画像を読込む

Sprite image = Resources.Load<Sprite> ("Images/enemy/enemy000");

と、書くとimageに画像ファイルを読み込むことができます。Resourcesフォルダの中にある画像だけが対象となっているようで、ファイルの拡張子はいらないようです。
型をTexture2DにするとGUIやTextureで使える画像として読込むことができるようです。
もしかしたら同じ要領でいろんなファイルやプレファブも取得できるのかもしれません(まだ試していませんが)。

フォルダごとまとめて読込みたい場合

Sprite[] image = Resources.LoadAll<Sprite> ("Images/enemy/");

こうすればフォルダ内にある画像をまとめて配列に読み込めるようです。
あとは必要な画像を配列から検索して取り出して使えます。

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