programatically setting colours

First off, I’m new to unity, I’m a software engineer and I’ve done a bit of graphics before and made simple games, all in code though importing models directly.

I am not creating a game but need the web player to display a model that can be navigated so unity seems like the tool to use. This model is made up of several thousand very simple objects; a few polygons each.

At run time I need to check each object against some data that I will fetch to choose a colour for each one. My understanding is that I can add a script to an object,

But really what Id like is to run a function once for every object on startup and then leave it. Is this possible?

If I am reading our question correctly, yes.

From your background you should be aware of the basic functionality of the Start function, it’s called only once at the start.

If you set the tag of your objects to have a specific name, you can use Find Objects With Tag to locate all the objects tagged with a certain name.

From here you can add them to an array and iterate through them setting the color, you can use Renderer.material to do that.

Hope that helps!

[EDIT] Just knocked this up…

void Start() {
    GameObject[] shapes = GameObject.FindGameObjectsWithTag("Shape");
    
    foreach (GameObject shape in shapes)
    {
        shape.renderer.material.color = Color.Red;
    }
}

Thanks very much!