-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangeColor.cs
executable file
·50 lines (41 loc) · 1.13 KB
/
ChangeColor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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<Renderer>() != null)
c = GetComponent<Renderer>().material.color;
else if (GetComponent<Light>() != null)
c = GetComponent<Light>().color;
c[channel] = value;
if (GetComponent<Renderer>() != null)
GetComponent<Renderer>().material.color = c;
else if (GetComponent<Light>() != null)
GetComponent<Light>().color = c;
}
public void OnPointerClick(PointerEventData data)
{
if (GetComponent<Renderer>() != null)
GetComponent<Renderer>().material.color = new Color(Random.value, Random.value, Random.value, 1.0f);
else if (GetComponent<Light>() != null)
GetComponent<Light>().color = new Color(Random.value, Random.value, Random.value, 1.0f);
}
}