美文网首页
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 随机颜色

    直接上码:

  • Unity-生成随机颜色

    简单随机颜色直接设置RGB为随机数,不过如果想得到特殊随机颜色,比如明度相同色调不同的若干随机色,就需要使用HSV...

  • 随机颜色

    调用函数即可 会返回一个随机的rgb

  • 随机颜色

    // UIColor+Hex.m创建继承于UIColor的类别 随机颜色 UIColor+Hex.h + (UIC...

  • 随机颜色

    - (UIColor*)randomColor {CGFloat red =arc4 random()%255/2...

  • 随机颜色

    flutter 产生随机颜色 相关代码如下: 需要导入以下两个 有了随机颜色妈妈再也不用但心选择颜色了~ 哈哈哈哈...

  • 随机颜色

    //随机颜色 intR = (arc4random() % 256) ; intG = (arc4rand...

  • 随机颜色

  • 随机颜色

  • 随机颜色

网友评论

      本文标题:Unity 随机颜色

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