I want to change the color of an object with a GUI Silder - The object has a number of children and I want to change their color as well - the Hierarchy looks like this.
Gameobject
Mesh 1
Mesh 2
Mesh 3
Each child object has a mesh renderer with 1 element - which has Reflective/Specular shader
This is the code I have been using - I can get the GUI Sliders to show up an work but cannot figure out how to get it to change the color of my objects
using UnityEngine;
using System.Collections;
public class ChangeColor : MonoBehaviour {
//public Color myColor;
private float rSlider = 0.0f;
private float bSlider = 0.0f;
private float gSlider = 0.0f;
public GameObject slab;
private Color myColor;
public MeshRenderer rend;
void Start () {
rend = GetComponentInChildren<MeshRenderer>();
}
void OnGUI () {
myColor = RGBSlider (new Rect (10,10,200,10), myColor);
}
Color RGBSlider (Rect screenRect, Color rgb) {
rSlider = GUI.HorizontalSlider (screenRect, rSlider, 0.0f, 1.0f);
// <- Move the next control down a bit to avoid overlapping
screenRect.y += 20;
gSlider = GUI.HorizontalSlider (screenRect, gSlider, 0.0f, 1.0f);
// <- Move the next control down a bit to avoid overlapping
screenRect.y += 20;
bSlider = GUI.HorizontalSlider (screenRect, bSlider, 0.0f, 1.0f);
return rgb;
slab.GetComponentInChildren<MeshRenderer>.material.color = myColor;
}
}
i have tried a number of lines at the end but they all give errors
renderer.material.color = myColor;
renderer.material.color = new color (rSlider, gSlider, bSlider);
GameObject.GetComponentInChildren.material.color etc;
gameObjcet.GetCompnentsInchildren.render.material.color etc
Any help much appreciated