Hi all. I am trying to make a script where I can re-color gameobjects.
The problem is that my code is not accessing the materials at all…
Here is what I’ve got:
public class JoesColorPicker : MonoBehaviour {
public GameObject rend1;
public GameObject rend2;
public bool WingsUIActive;
public bool HullUIActive;
void Start ()
{
rend1 = GetComponent<Renderer> ().material;
rend2 = GameObject.GetComponent<Renderer> ().material;
rend1.GetComponent<Renderer>().material.shader = Shader.Find ("Standard");
rend2.GetComponent<Renderer>().material.shader = Shader.Find ("Standard");
HullUIActive = true;
WingsUIActive = false;
}
public void RedButton ()
{
if (HullUIActive) {
rend1.material.SetColor("_Color", Color.red);
}else
rend2.material.SetColor("_Color", Color.red);
}
}
I’m confused by what you are doing. (Your start is confusing) You have declared two GameObjects but then you are trying to assign a material to them with GetComponent. This should be throwing you an error.
Can you better explain what you are wanting to do? Gameobjects don’t have colors, so I’m just assuming you have a 3d object with a texture?
What I am trying to do is simply access the renderer of a gameObject so I can change color of it.
I am currently getting tons of errors like “Can not convert type UnityEngine.Material to UnityEngine.GameObject”
I could not find any useful information on this in the documentation so I am hoping to get some help here
Please let me know if you need any more information
I am not trying to create a new material to assign the gameobject. I want to access the existing one and change its color.