Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created August 8, 2017 23:31
Show Gist options
  • Save unity3dcollege/53baec9c4d7eb32b9eea4e7bd8d39cff to your computer and use it in GitHub Desktop.
Save unity3dcollege/53baec9c4d7eb32b9eea4e7bd8d39cff to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
public class ChooseRandomColor : MonoBehaviour
{
private void Start()
{
GetComponent<Button>().onClick.AddListener(ChangeImageColor);
}
private void ChangeImageColor()
{
GetComponent<Image>().color = RandomColor();
}
private Color RandomColor()
{
return new Color(
UnityEngine.Random.Range(0f, 1f),
UnityEngine.Random.Range(0f, 1f),
UnityEngine.Random.Range(0f, 1f)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment