Get A Random Color Unity Code Example


Example 1: unity generate random color


//using Color
Color randomColor = new Color(
Random.Range(0f, 1f), //Red
Random.Range(0f, 1f), //Green
Random.Range(0f, 1f), //Blue
1, //Alpha (transparency)
);

//using Color32
Color32 randomColor = new Color32(
Random.Range(0, 255), //Red
Random.Range(0, 255), //Green
Random.Range(0, 255), //Blue
255, //Alpha (transparency)
);

Example 2: unity random color


using UnityEngine;public class ColorOnClick : MonoBehaviour
{
void OnMouseDown()
{
// Pick a random, saturated and not-too-dark color
GetComponent<Renderer>().material.color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
}
}

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android SDK Location Should Not Contain Whitespace, As This Cause Problems With NDK Tools