ClickExercise.cs
2.11 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
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; //버튼들의 부모
private void Start()
{
btnParent = GameObject.Find("BtnGroup").gameObject; // "부모의 이름"으로 찾습니다.
}
public void 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")
{
btnImage.texture = Resources.Load("SideHiKick_on", typeof(Texture2D)) as Texture2D;
}
}
}