ClickExercise.cs
2.86 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
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 quad; //커서
Vector3 pos;
private float timer;
private void Start()
{
btnParent = GameObject.Find("BtnGroup").gameObject; // "부모의 이름"으로 찾습니다.
quad = GameObject.Find("Quad_s").gameObject;
pos = quad.transform.position;
Debug.Log(pos);
}
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")
{
btnImage.texture = Resources.Load("Squat_on", typeof(Texture2D)) as Texture2D;
}
else if (btnImage.name == "Lunge")
{
btnImage.texture = Resources.Load("Lunge_on", typeof(Texture2D)) as Texture2D;
}
else if (btnImage.name == "SideHiKick")
{
Debug.Log("SideHighKick");
btnImage.texture = Resources.Load("SideHiKick_on", typeof(Texture2D)) as Texture2D;
}
}
void Update()
{
pos = quad.transform.position;
Debug.Log(pos);
/*
if (pos.x >= 155 && pos.x <= 185 && pos.y >= 13 && pos.y <= 60) {
btnImage2.texture = Resources.Load("Squat_off", typeof(Texture2D)) as Texture2D;
btnImage.texture = Resources.Load("SideHiKick_on", typeof(Texture2D)) as Texture2D;
btnImage2.texture = Resources.Load("Lunge_off", typeof(Texture2D)) as Texture2D;
}
*/
}
}