ゲームのインベントリのようにフレーム+アイテムの画像を重ねる方法を書いていきます。
1.前準備
ボタンオブジェクトを作成して、その子オブジェクトとしてUI Imageを作成します。

2.スクリプト作成
コードを作成します
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ItemIcon : MonoBehaviour
{
public Sprite frameImage;
public Sprite itemImage;
public Button btn;
// Start is called before the first frame update
void Start()
{
//ボタンの画像を変更する
btn.GetComponent<Image>().sprite = frameImage;
//ボタンについている1番目の子オブジェクトの画像を変更する
btn.transform.GetChild(0).GetComponent<Image>().sprite = itemImage;
}
}
3.動作確認
ゲーム開始時にセットした画像が反映されます

コメント