Created
August 8, 2017 23:31
-
-
Save unity3dcollege/53baec9c4d7eb32b9eea4e7bd8d39cff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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