From 115f77bda0246a00f6e17469685c67746bdbd29d Mon Sep 17 00:00:00 2001 From: nirav Date: Sat, 12 Dec 2020 07:18:36 +0000 Subject: Initial commit --- Assets/SampleUI/Scripts/ChangeColor.cs | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 Assets/SampleUI/Scripts/ChangeColor.cs (limited to 'Assets/SampleUI/Scripts/ChangeColor.cs') diff --git a/Assets/SampleUI/Scripts/ChangeColor.cs b/Assets/SampleUI/Scripts/ChangeColor.cs new file mode 100755 index 0000000..f7e474b --- /dev/null +++ b/Assets/SampleUI/Scripts/ChangeColor.cs @@ -0,0 +1,50 @@ +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +public class ChangeColor : MonoBehaviour, IPointerClickHandler +{ + void OnEnable () + { + } + + public void SetRed(float value) + { + OnValueChanged(value, 0); + } + + public void SetGreen(float value) + { + OnValueChanged(value, 1); + } + + public void SetBlue(float value) + { + OnValueChanged(value, 2); + } + + public void OnValueChanged(float value, int channel) + { + Color c = Color.white; + + if (GetComponent() != null) + c = GetComponent().material.color; + else if (GetComponent() != null) + c = GetComponent().color; + + c[channel] = value; + + if (GetComponent() != null) + GetComponent().material.color = c; + else if (GetComponent() != null) + GetComponent().color = c; + } + + public void OnPointerClick(PointerEventData data) + { + if (GetComponent() != null) + GetComponent().material.color = new Color(Random.value, Random.value, Random.value, 1.0f); + else if (GetComponent() != null) + GetComponent().color = new Color(Random.value, Random.value, Random.value, 1.0f); + } +} -- cgit v1.2.3