facebook twitter hatena line email

「Unity/Csharp/画像ロード」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==画像ロード== Sprite sp = Resources.Load<Sprite>("gazo"); GameObject gameObj = new GameObject(); Image image = gameObj.AddComponent<Image>(); image.sprite = sp;...」)
 
行1: 行1:
==画像ロード==
+
==画像ロード(Imageを使う方法)==
 
  Sprite sp = Resources.Load<Sprite>("gazo");
 
  Sprite sp = Resources.Load<Sprite>("gazo");
 
  GameObject gameObj = new GameObject();
 
  GameObject gameObj = new GameObject();
行8: 行8:
 
  gameObj.transform.localScale = new Vector3 (1f, 1f, 0);
 
  gameObj.transform.localScale = new Vector3 (1f, 1f, 0);
  
==slice画像ロード==
+
==slice画像ロード(Imageを使う方法)==
 
  Sprite[] sprites = Resources.LoadAll<Sprite>("gazo");
 
  Sprite[] sprites = Resources.LoadAll<Sprite>("gazo");
 
  Sprite sp = System.Array.Find<Sprite>( sprites, (sprite) => sprite.name.Equals("gazo_1"));
 
  Sprite sp = System.Array.Find<Sprite>( sprites, (sprite) => sprite.name.Equals("gazo_1"));
行17: 行17:
 
  gameObj.transform.name = "gazo_1";
 
  gameObj.transform.name = "gazo_1";
 
  gameObj.transform.localScale = new Vector3 (1f, 1f, 0);
 
  gameObj.transform.localScale = new Vector3 (1f, 1f, 0);
 +
 +
 +
==画像ロード(SpriteRendererを使う方法)==
 +
Sprite sp = Resources.Load<Sprite>("gazo");
 +
GameObject gameObj = new GameObject();
 +
SpriteRenderer spriteRenderer = gameObj.AddComponent<SpriteRenderer>();
 +
spriteRenderer.sprite = sp;
 +
gameObj.transform.parent = FindObjectOfType<Canvas>().transform;
 +
gameObj.transform.localScale = new Vector3 (83, 83, 0);
 +
gameObj.transform.name = "gazo";
 +
 +
==slice画像ロード(SpriteRendererを使う方法)==
 +
Sprite[] sprites = Resources.LoadAll<Sprite>("gazo");
 +
Sprite sp = System.Array.Find<Sprite>( sprites, (sprite) => sprite.name.Equals("gazo_1"));
 +
GameObject gameObj = new GameObject();
 +
SpriteRenderer spriteRenderer = gameObj.AddComponent<SpriteRenderer>();
 +
spriteRenderer.sprite = sp;
 +
gameObj.transform.parent = FindObjectOfType<Canvas>().transform;
 +
gameObj.transform.localScale = new Vector3 (83, 83, 0);
 +
gameObj.transform.name = "gazo_1";

2017年9月21日 (木) 23:48時点における版

画像ロード(Imageを使う方法)

Sprite sp = Resources.Load<Sprite>("gazo");
GameObject gameObj = new GameObject();
Image image = gameObj.AddComponent<Image>();
image.sprite = sp;
gameObj.transform.parent = FindObjectOfType<Canvas>().transform;
gameObj.transform.name = "gazo";
gameObj.transform.localScale = new Vector3 (1f, 1f, 0);

slice画像ロード(Imageを使う方法)

Sprite[] sprites = Resources.LoadAll<Sprite>("gazo");
Sprite sp = System.Array.Find<Sprite>( sprites, (sprite) => sprite.name.Equals("gazo_1"));
GameObject gameObj = new GameObject();
Image image = gameObj.AddComponent<Image>();
image.sprite = sp;
gameObj.transform.parent = FindObjectOfType<Canvas>().transform;
gameObj.transform.name = "gazo_1";
gameObj.transform.localScale = new Vector3 (1f, 1f, 0);


画像ロード(SpriteRendererを使う方法)

Sprite sp = Resources.Load<Sprite>("gazo");
GameObject gameObj = new GameObject();
SpriteRenderer spriteRenderer = gameObj.AddComponent<SpriteRenderer>();
spriteRenderer.sprite = sp;
gameObj.transform.parent = FindObjectOfType<Canvas>().transform;
gameObj.transform.localScale = new Vector3 (83, 83, 0);
gameObj.transform.name = "gazo";

slice画像ロード(SpriteRendererを使う方法)

Sprite[] sprites = Resources.LoadAll<Sprite>("gazo");
Sprite sp = System.Array.Find<Sprite>( sprites, (sprite) => sprite.name.Equals("gazo_1"));
GameObject gameObj = new GameObject();
SpriteRenderer spriteRenderer = gameObj.AddComponent<SpriteRenderer>();
spriteRenderer.sprite = sp;
gameObj.transform.parent = FindObjectOfType<Canvas>().transform;
gameObj.transform.localScale = new Vector3 (83, 83, 0);
gameObj.transform.name = "gazo_1";