How to change prefab color with C# code.

Hello everyone,

Are there some solutions that we can change the prefab’s color at the runtime. My prefab is UI Image as bellow:


And the bellow is oval prefab:

I have created oval image by Photoshop with background color is Red. I want to change from Red to Yellow, can I do this? I have tried:
numTransform.GetComponent ().material.color = Color.yellow;

But the above solution doesn’t work.

I think the reason is I have used an image with prefab and need to reload sprite property at the runtime with yellow oval image.

Just want to know are there some solutions to change color for this situation?

By the way, the bellow is small code that I Instantiate a prefab:

Transform numTransform = Instantiate (numPrefab) as Transform;
//numTransform.GetComponent ().color = new Color (255, 255, 225, 100);
//numTransform.GetComponent ().material.SetColor (“_Color”, Color.yellow);
numTransform.GetComponent ().material.color = Color.yellow;

numTransform.position = new Vector3 (transform.position.x, transform.position.y, 0);
numTransform.SetParent (gameObject.transform);

Thank you.

Create a white oval image in photoshop. and in the script try this:

public Image imgOval;

imgOval.color =;


imgOval.color = Color.yellow;

Thanks Aisenhein.