Question by
The_Awesome_One · Sep 25, 2015 at 03:38 PM ·
unity 5uibuttons
Giving a UI button a Color at Start
I'm trying to assign random colors o an array of UI buttons. I have an array of Colors and an array of buttons but once I get get down to AssignColor I can't say b.Color.
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class match : MonoBehaviour {
public Image[] images;
public float time = 30.0f;
public float _score;
public GameObject pausePanel;
public Color[] colors;
public Button[] buttons;
public ColorBlock theColor;
// Use this for initialization
void Start () {
_score = 0.0f;
colors = new Color[3];
buttons = new Button[16];
theColor = GetComponent<Button>().colors;
colors [0] = Color.red;
colors [1] = Color.blue;
colors [3] = Color.green;
}
// Update is called once per frame
void Update () {
AssignColor ();
time -= Time.deltaTime;
if (time <= 0) {
time = 0.0f;
}
if (time == 0 && _score == 0) {
pausePanel.SetActive (true);
}
}
void OnGUI()
{
GUI.Box (new Rect (10, 10, 30, 20), "" + time.ToString ("0"));
GUI.Box (new Rect (85, 410, 30, 20), "" + _score.ToString ("0"));
}
void AssignColor()
{
int colornum = Random.Range (0, colors.Length);
foreach (Button b in buttons) {
}
}
}
Comment