ClickExercise.cs
6.94 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class ClickExercise : MonoBehaviour
{
RawImage btnImage;
RawImage btnImage2;
GameObject btnParent; //버튼들의 부모
GameObject follow; //커서
Vector3 pos;
private float timer;
public static string selected_exercise;
private void Start()
{
btnParent = GameObject.Find("BtnGroup").gameObject; // "부모의 이름"으로 찾습니다.
follow = GameObject.Find("follow").gameObject;
pos = follow.transform.position;
follow.transform.position = new Vector3(400, 0, 200);
//Debug.Log(pos);
selected_exercise = "Squat"; //default로 스쿼트가 선택되어 있으므로
}
/*
public void GetBtn()
{
Debug.Log("GetBtn");
GameObject tempBtn = EventSystem.current.currentSelectedGameObject;
btnImage = tempBtn.GetComponent<RawImage>(); // 해당 오브젝트의 image 컴포넌트를 받음
int btnLength = btnParent.transform.childCount; // 자식의 갯수를 파악
Debug.Log(btnLength);
for (int i = 0; i < btnLength; i++) // 자식의 갯수 만큼 i++ 실행
{
//transfrom.Getchild(i)를 통해 버튼을 하나씩 색인
GameObject tempBtns = btnParent.transform.GetChild(i).gameObject; // 해당 버튼 이미지 컴포넌트를 불러온 후 변경
btnImage2 = tempBtns.GetComponent<RawImage>();
if (tempBtns.name == "Squat")
{
btnImage2.texture = Resources.Load("Squat_off", typeof(Texture2D)) as Texture2D;
}
else if (tempBtns.name == "Lunge")
{
btnImage2.texture = Resources.Load("Lunge_off", typeof(Texture2D)) as Texture2D;
}
else if (tempBtns.name == "SideHiKick")
{
btnImage2.texture = Resources.Load("SideHiKick_off", typeof(Texture2D)) as Texture2D;
}
//Debug.Log(tempBtns);
}
if (btnImage.name == "Squat")
{
Debug.Log("Squat");
selected_exercise = "Squat";
btnImage.texture = Resources.Load("Squat_on", typeof(Texture2D)) as Texture2D;
}
else if (btnImage.name == "Lunge")
{
Debug.Log("Lunge");
selected_exercise = "Lunge";
btnImage.texture = Resources.Load("Lunge_on", typeof(Texture2D)) as Texture2D;
}
else if (btnImage.name == "SideHiKick")
{
Debug.Log("SideHighKick");
selected_exercise = "SideHighKick";
btnImage.texture = Resources.Load("SideHiKick_on", typeof(Texture2D)) as Texture2D;
}
//Squat x:60~285 , y:355~640 , z:300
//SideHighKick x:400 ~ 625, y:355~640, z:300
//Lunge x:735~965 , y:355~640 , z:300
}
*/
void Update()
{
pos = follow.transform.position;
// Debug.Log(pos);
if (pos.x >= 60 && pos.x <= 285 && pos.y >= 335 && pos.y <= 640 && pos.z == 200) {
//스쿼트
timer += Time.deltaTime;
Debug.Log("Timer: " + timer);
if (timer > 2.5)
{
Debug.Log("Clicked");
//////
selected_exercise = "Squat"; //Squat 넘겨줌
GameObject tempBtn = btnParent.transform.GetChild(3).gameObject;
btnImage = tempBtn.GetComponent<RawImage>(); // 해당 오브젝트의 image 컴포넌트를 받음
if (btnImage.name == "Squat")
{
Debug.Log("Squat");
btnImage.texture = Resources.Load("Squat_on", typeof(Texture2D)) as Texture2D;
}
GameObject sidehk = btnParent.transform.GetChild(2).gameObject;
btnImage2 = sidehk.GetComponent<RawImage>();
btnImage2.texture = Resources.Load("SideHiKick_off", typeof(Texture2D)) as Texture2D;
GameObject lunge = btnParent.transform.GetChild(1).gameObject;
btnImage2 = lunge.GetComponent<RawImage>();
btnImage2.texture = Resources.Load("Lunge_off", typeof(Texture2D)) as Texture2D;
}
}
else if(pos.x >= 400 && pos.x <= 625 && pos.y >= 335 && pos.y <= 640 && pos.z == 200){
//사이드하이킥
timer += Time.deltaTime;
Debug.Log("Timer: " + timer);
if (timer > 2.5)
{
Debug.Log("Clicked");
/////
selected_exercise = "SideHiKick"; //SideHiKick 넘겨줌
GameObject tempBtn = btnParent.transform.GetChild(2).gameObject;
btnImage = tempBtn.GetComponent<RawImage>(); // 해당 오브젝트의 image 컴포넌트를 받음
if (btnImage.name == "SideHiKick")
{
Debug.Log("SideHiKick");
btnImage.texture = Resources.Load("SideHiKick_on", typeof(Texture2D)) as Texture2D;
}
GameObject squat = btnParent.transform.GetChild(3).gameObject;
btnImage2 = squat.GetComponent<RawImage>();
btnImage2.texture = Resources.Load("Squat_off", typeof(Texture2D)) as Texture2D;
GameObject lunge = btnParent.transform.GetChild(1).gameObject;
btnImage2 = lunge.GetComponent<RawImage>();
btnImage2.texture = Resources.Load("Lunge_off", typeof(Texture2D)) as Texture2D;
}
}
else if (pos.x >= 735 && pos.x <= 965 && pos.y >= 335 && pos.y <= 640 && pos.z == 200)
{
//런지
timer += Time.deltaTime;
Debug.Log("Timer: " + timer);
if (timer > 2.5)
{
Debug.Log("Clicked");
//////
selected_exercise = "Lunge"; //Lunge 넘겨줌
GameObject tempBtn = btnParent.transform.GetChild(1).gameObject;
btnImage = tempBtn.GetComponent<RawImage>(); // 해당 오브젝트의 image 컴포넌트를 받음
if (btnImage.name == "Lunge")
{
Debug.Log("Lunge");
btnImage.texture = Resources.Load("Lunge_on", typeof(Texture2D)) as Texture2D;
}
GameObject squat = btnParent.transform.GetChild(3).gameObject;
btnImage2 = squat.GetComponent<RawImage>();
btnImage2.texture = Resources.Load("Squat_off", typeof(Texture2D)) as Texture2D;
GameObject sidehk = btnParent.transform.GetChild(2).gameObject;
btnImage2 = sidehk.GetComponent<RawImage>();
btnImage2.texture = Resources.Load("SideHiKick_off", typeof(Texture2D)) as Texture2D;
}
}
}
}