美文网首页
Unity 随机颜色

Unity 随机颜色

作者: 木子才 | 来源:发表于2017-05-11 15:48 被阅读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);
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:Unity 随机颜色

          本文链接:https://www.haomeiwen.com/subject/jwiotxtx.html