- Home /
Changing colors of a material
Hello,
I'm making a Bomberman clone. I want bombs to change color before they explode.
Here's my current code:
void Colorchange()
{
timer -= Time.deltaTime;
if (timer < 400 && checkColor)
{
checkColor = false;
Debug.Log("Red");
gameObject.transform.GetChild(0).transform.GetChild(0).GetComponent<Renderer>().material.color = Color.red;
}
}
The debug log shows up in the console at the correct time, but the color stays the same.
I haven't found any working alternatives by looking on this forum, either.
Any tips ?
I'm also working on the lightweight render pipeline, if that makes any difference.
Answer by dorusoftware · Jul 24, 2020 at 08:23 PM
Try removing the second "transform" like this
gameObject.transform.GetChild(0).GetChild(0).GetComponent<Renderer>().material.color = Color.red;
Your answer
Follow this Question
Related Questions
SRP URP Changing values of a material being shared by many objects in the Editor 0 Answers
change material on background 4 Answers
How to find all gameobjects that use the same material and change it? 1 Answer
How to get pixel coordinates when mouse click on Sprite Renderer 0 Answers
rendering mode "Fade" results in culling disorder? 0 Answers