I am simply trying to change the sprite renderer’s color to a random color when I click the button. This works 100% fine in editor play mode but only does not work when I build it. I’ve tried Color, Color32…I’ve tried everything and have found dozens of people with the same problem…never finding a solution.
public Color32[] colors;
int index;
Color32 randomColor;
void Start()
{
torso = GameObject.Find("Torso").GetComponent<SpriteRenderer>();
head = GameObject.Find("Head").GetComponent<SpriteRenderer>();
armL = GameObject.Find("ArmL").GetComponent<SpriteRenderer>();
armR = GameObject.Find("ArmR").GetComponent<SpriteRenderer>();
}
public void RandomColor()
{
Color32[] colors = { new Color32(29, 204, 61, 255), new Color32(236, 159, 33, 255), new Color32(156, 190, 15, 255), new Color32(31, 134, 157, 255) };
int index;
index = Random.Range(0, colors.Length);
Color32 randomColor = colors[index];
torso.material.SetColor("_Color", randomColor);
head.material.SetColor("_Color", randomColor);
armL.material.SetColor("_Color", randomColor);
armR.material.SetColor("_Color", randomColor);
}
Ultimately this is going to depend on the shader your material is using. If it’s built in render pipeline and the standard shader, then material.color alone should suffice. If it’s something else, then it will depend on the shader. Every shader uses a different name for its various parameters, and not all of them support a multiplicative blend color.
Yeah, I tried BaseColor with URP too. Ideally, I’d use the Default Sprite shader…That’s the only shader where i can change the sprite renderer’s color and have it accurately reproduced and bright. I just want it to change like this during build run: https://www.youtube.com/watch?v=pFo9EFVo0u8
Try using “transform.GetComponent().color” instead of “material.setcolor”, maybe unity is using the spriterenderer color in the inspector instead of the material’s.