Hi all,
So I’m on the merry journey of creating my first Unity game, but hit another small hiccup. So, let me explain:
I know I can use:
gameobjectname.renderer.material.SetColor("_Color", colorVar);
I know that because I read the script reference, and made a simple test scene with a primitive to test it. It works perfectly.
But for some reason, in my game, it doesn’t work, visually the colour remains unchanged. But, if I do GetColor for the material I just changed, before the change code, and after it, the two values are different - as if the colour has been changed. Also, I get no errors whilst the scene is running.
This code is part of quite a long function that is basically loading a save game, but here’s the relevant section:
GameObject stockShell = GameObject.Find("stockShell");
// convert hex to colour
Color playerCarColourA = HexToColor(currentCarSplitPaintHexA);
Color playerCarColourB = HexToColor(currentCarSplitPaintHexB);
// apply player colour
stockShell.renderer.material.SetColor("_Color", playerCarColourA);
stockShell.renderer.material.SetColor("_Color2", playerCarColourB);
I’ve tried changing playerCarColourA and B to things like Color.red - and I get the same result: no visual change, but doing a before and after GetColor, the console is telling me the value has changed. No errors. But no visual change.
Any ideas folks?
Thanks
Matt