Changing color of a material before instantiating

So I’m doing this room designer type game. In the top left the user will select the chair which opens up the top right menu which will be buttons with colors on them. What I plan on doing is selecting a color will change the color of a chair then it instantiates it.

I’ve tried doing with sharedmaterials but I don’t want to change all of the prefabs color, anyway I can do it individually?

Have you got the code for instantiation? should post it here so we can help :stuck_out_tongue:

Not sure how to post snippets of code, I’m still new. But here in png form. Basically it’s all done in buttons and the chair spawns at a fixed location. Nothing much. It’s called SpawnRed because I was trying to change the color to red before spawning the chair and it’s an onclick on the button with the text “Red”

it’s best to use code tags and copy n paste the code inside the tags,

Anyways, here’s how i would change the material of an object, just tested it works :slight_smile:

using UnityEngine;
using System.Collections;

public class Instantiate : MonoBehaviour {

    // Use this for initialization
   public GameObject go;
    Color color;
    void Start ()
    {
        color = new Color(1, 0, 0, 1); // set to red (perhaps u can change this in another button/scroller
    }
   
    // Update is called once per frame
    void Update ()
    {
   
    }

    public void instantiate()
    {
        GameObject obj;
        obj = (GameObject)Instantiate(go, new Vector3(0, 0, 0), Quaternion.identity);
        obj.GetComponent<Renderer>().material.color = new Color(color.r, color.g, color.b, color.a); // set the material to the color we said in the Start()
    }
}