直接上码:
public class test04 : MonoBehaviour {
//对象
private GameObject obj;
// Use this for initialization
void Start () {
obj = GameObject.Find ("Cube");
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
if (GUILayout.Button ("随机颜色", GUILayout.Height (50))) {
float red = Random.Range (0.0f, 1.0f);
float green = Random.Range (0.0f, 1.0f);
float blue = Random.Range (0.0f, 1.0f);
Renderer render = obj.GetComponent<Renderer> ();
render.material.color = new Color(red, green, blue);
}
}
}