what is the best way to modify a property of a prefab?

Not sure I’ve worded that correctly…

But let’s say I have a Cube prefab. I instantiated 5X5 Cube prefabs so that they form a 5X5 grid.

Now, I want a Cube to have a property, something like “isSet”. If isSet is true, then the Cube is yellow. Otherwise, the Cube is red (just the default color).

So, in some main script, I have a loop that creates the grid of Cubes:

public class MainScript: MonoBehavior {
    public Transform cube;
    public start() {
        SomeScript script;
        GameObject obj;
        for (int i=0... {
            for (int j=0... {
                obj = (GameObject)Instantiate(cube....
                script = obj.GetComponent<ZoneTypeScript>();
                script.isSet = true;
            }
        }
    }
}

Now, a prefab is a prefab, so it’s not like I can just add a property to it. But I could add a MonoBehaviour script that perhaps has the property I want to set, no? But how would I change the property in the loop above?

Thanks.

Instantiate() returns the GameObject it just instantiated. Once it does, do whatever you want to it.

I think it works this way:

1- Add a script to your prefab. The script (“ScriptX”) has the properties you want (propertyW).

2- You create the object:

    GameObject obj = (GameObject)Instantiate(Cube_Prefab,vec3,Quaternion.identity);

3- You change the property by the script:

    obj.GetComponent<ScriptX>().propertyW = "Test";