(スクリプト)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoxColorTag : MonoBehaviour
{
private string matName;
void Start()
{
matName = GetComponentt<MeshRenderer>().material.name;
if (matName == "Red (Instance)")
{
this.gameObject.tag = "Red";
}
else if (matName == "Blue (Instance)") // ★(Instance)を付けるのがポイント!
{
this.gameObject.tag = "Blue";
}
}
}
(実行結果)