12.13 캐릭터 선택하기(랜덤포함)
C#/실습 2019. 12. 13. 17:07코드:
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Ingame : MonoBehaviour
{
public UISelectedButton[] btns;
public UISelectedButton randomBtn;
public string[] btnNames;
public Image image;
private Coroutine changeC;
private GameObject selectedObject;
public Button selectBtn;
public Text selectedText;
public void Awake()
{
Debug.Log("Ingame: Awake");
}
private void Start()
{
selectBtn.onClick.AddListener(() =>
{
StopAllCoroutines();
});
int i = 0;
foreach(var btn in btns)
{
btn.Onselected = () =>
{
foreach(var btn2 in btns)
{
btn2.gameObject.transform.GetChild(1).gameObject.SetActive(false);
}
StopAllCoroutines();
btn.gameObject.transform.GetChild(1).gameObject.SetActive(true);
this.selectedObject = btn.gameObject;
};
i++;
}
randomBtn.Onselected = () =>
{
changeC = StartCoroutine(changeImage());
foreach (var btn2 in btns)
{
btn2.gameObject.transform.GetChild(1).gameObject.SetActive(false);
this.selectedObject = randomBtn.gameObject;
randomBtn.gameObject.transform.GetChild(1).gameObject.SetActive(true);
}
};
randomBtn.Init("random");
}
IEnumerator changeImage()
{
int i=0;
while(true)
{
if(i >= 4)
{
i = 0;
}
this.selectedObject = btns[i].gameObject;
yield return new WaitForSeconds(0.2f);
i++;
}
}
public void Init()
{
Debug.Log("게임 초기화");
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UISelectedButton : MonoBehaviour
{
public Button btn;
public System.Action Onselected;
public Text text;
void Start()
{
this.btn.onClick.AddListener(() =>
{
this.Onselected();
});
}
public void Init(string text)
{
this.gameObject.transform.GetChild(1).gameObject.SetActive(false);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
씬전환은 덤이다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class App : MonoBehaviour
{
private void Awake()
{
}
void Start()
{
var oper = SceneManager.LoadSceneAsync("Ingame", LoadSceneMode.Additive);
oper.completed += (ao) =>
{
Debug.Log("Ingame 씬 로드완료");
};
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'C# > 실습' 카테고리의 다른 글
12.17 Unity Editor 활용해 실시간으로 Json 파일 만들기 (0) | 2019.12.17 |
---|---|
12.16 UI 버튼 만들기 (0) | 2019.12.16 |
12.09 충돌감지와 sprite활용하기(delegate) (0) | 2019.12.09 |
12.06 드래곤플라이트 구현 (0) | 2019.12.06 |
12.05 유닛 바라보기 (LookAt 메서드 사용X) (1) | 2019.12.05 |