gameObject changes color in inspector but not in game

So I have a gameObject which when imported is black. I just want to change the color to say green. So I added this code to the gameObject. gameObject.GetComponent ().material.color = Color.green;
and it creates a new ‘Spries-Default (Instance)’ tab in the inspector with a picture of the gameObject in green but not in the actual game. I am pretty confused as to why it is not showing in the game, any help here?

Try this code :

    public MeshRenderer yourRenderer;
	public Color colorWanted;

	private Material yourMaterial;

	void Start () {
		yourMaterial = yourRenderer.material;
		yourMaterial.color = colorWanted;
	}

Hope this will help :slight_smile:

Check your shader used on the gameObject. Changing the color might be changing a color…but not the correct color needed.

I had the same problem. Turned out that I was doing a fadeout in an animation at the same time, which overrides all the rgb-color changes I made. Took a good while to figure out :slight_smile: