Unity 随机颜色

2017-05-11  本文已影响0人  木子才

直接上码:

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);
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读