Z
Z
Zimaell2020-07-28 18:18:58
Unity
Zimaell, 2020-07-28 18:18:58

How to change the color of a prefab?

I do this, for example, the prebuff will consist of such components
Tree - an empty object, I also added MeshRenderer
---BaseTree - cube
---HeadTree - sphere,
then I want to change the color of the whole tree

Renderer MainRenderer;

void Start(){
  MainRenderer = GetComponent<Renderer>();
  }

public void SetTransparent(bool available){
  if (available) MainRenderer.material.color = Color.green;
    else MainRenderer.material.color = Color.red;
  }

nothing happens when replaced with a public variable
public Renderer MainRenderer;
// start убрать

and put BaseTree or HeadTree there, then it is this part that will change color, but the whole thing doesn’t work, even if you put the prefab there ... Tell me
how to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-07-28
@GavriKos

EVERY MEshRenderer needs to change color. Those. array-list and loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question