-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiment_color.cs
129 lines (101 loc) · 4.07 KB
/
experiment_color.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class experiment_color : MonoBehaviour
{
public float limit; //色が変わりきる時間
float countT = 0; //経過時間
private Material BaseMaterial;
private Color ChangeColor;
private Color BufColor;
//変化させたい色
private float R ;
private float G ;
private float B ;
public GameObject hand;
private bool col;//衝突判定
public int ColorNumber = 0;//変わる色の切り替え
//public int ColorNumberCount = 0;
// Start is called before the first frame update
void Start()
{
BaseMaterial = this.GetComponent<Renderer>().material;//手のマテリアル
ChangeColor = BaseMaterial.color; //変色用変数
BufColor = BaseMaterial.color; //原色を保持する変数
Debug.Log(BaseMaterial.color.r);
}
// Update is called once per frame
void Update()
{
col = hand.GetComponent<handcollider>().c;
float deltaT = Time.deltaTime;
//if (Input.GetKeyDown(KeyCode.C))
//{
// ColorNumberCount += 1;
// if (ColorNumberCount == 3)
// {
// ColorNumberCount = 0;
// }
// ColorNumber = ColorNumberCount;
//}
if (col)//衝突したら
{
switch (ColorNumber)
{
case 0://変化なし
this.GetComponent<Renderer>().material.color = new Color(BufColor.r, BufColor.g, BufColor.b);
break;
case 1:// 実験暖色
countT += Time.deltaTime;
if (countT <= limit)
{
R = 1;
G = 0.674915864f;
B = 0.608067625f;
ChangeColor.r += ((R - BufColor.r) * deltaT / (limit));
ChangeColor.g += ((G - BufColor.g) * deltaT / (limit));
ChangeColor.b += ((B - BufColor.b) * deltaT / (limit));
this.GetComponent<Renderer>().material.color = new Color(ChangeColor.r, ChangeColor.g, ChangeColor.b);
if (countT>=limit)
{
Debug.Log("time = " + countT);
}
if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("time = " + countT);
Debug.Log("RED = " + ChangeColor.r);
Debug.Log("GREEN = " + ChangeColor.g);
Debug.Log("BLUE = " + ChangeColor.b);
}
}
break;
case 2:// 実験寒色
countT += Time.deltaTime;
if (countT <= limit)
{
R = 0.6977477f;
G = 0.813963967f;
B = 0.892456433f;
ChangeColor.r += ((R - BufColor.r) * deltaT / (limit));
ChangeColor.g += ((G - BufColor.g) * deltaT / (limit));
ChangeColor.b += ((B - BufColor.b) * deltaT / (limit));
this.GetComponent<Renderer>().material.color = new Color(ChangeColor.r, ChangeColor.g, ChangeColor.b);
if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("time = " + countT);
Debug.Log("RED = " + ChangeColor.r);
Debug.Log("GREEN = " + ChangeColor.g);
Debug.Log("BLUE = " + ChangeColor.b);
}
}
break;
}
}
else
{
ChangeColor = new Color(BufColor.r, BufColor.g, BufColor.b);
this.GetComponent<Renderer>().material.color = new Color(BufColor.r, BufColor.g, BufColor.b);
countT = 0;
}
}
}