Hi all , I am trying to change my Object tags on start based on what their material loaded into them is. I am using this Code.
What i've done is this code (Short example)
Material Red;
Material Blue;
Material Yellow;
void Start()
{
if (GetComponent().material == Red)
{
gameObject.tag = "Red";
}
if (GetComponent().material == Yellow)
{
gameObject.tag = "Yellow" ;
}
if (GetComponent().material == Blue)
{
gameObject.tag = "Blue";
}
}
I drag my materials into the Materials on unity , I also make sure to have the Tags in the Tag list AND i also drag the scripts onto my objects.
I get an Object reference not set to instance of an object error, Why ?
Also if people can verify what i'm doing above is correct code. Thanks
↧