12.19 게이지바 만들기
카테고리 없음 2019. 12. 19. 17:18코드:
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TestHQ2 : MonoBehaviour
{
public UIGauge uiGauge;
public Button btnUP;
public Button btnDown;
public btnCTRL btnCtrlUp;
public btnCTRL btnCtrlDown;
// Start is called before the first frame update
void Start()
{
btnCtrlUp = btnUP.GetComponent<btnCTRL>();
btnCtrlDown = btnDown.GetComponent<btnCTRL>();
//btnUP.onClick.AddListener(() => { uiGauge.fillImg.fillAmount += 0.1f; });//꾹누르기
//btnDown.onClick.AddListener(() => { uiGauge.fillImg.fillAmount -= 0.1f; });
//btnUP.onClick.AddListener(() => { uiGauge.GaugeUpbyC(); });//코루틴으로 10씩
//btnDown.onClick.AddListener(() => { uiGauge.GaugeDownbyC(); });
btnUP.onClick.AddListener(() => { uiGauge.GaugeUpbyDG(); });//두트윈으로 10씩
btnDown.onClick.AddListener(() => { uiGauge.GaugeDownbyDG(); });
}
// Update is called once per frame
void Update()
{
//if(btnCtrlUp.isBtnDown)//꾹누르기
//{
// uiGauge.fillImg.fillAmount += 0.01f;
//}
//else if(btnCtrlDown.isBtnDown)
//{
// uiGauge.fillImg.fillAmount -= 0.01f;
//}
}
}
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
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class UIGauge : MonoBehaviour
{
public Image fillImg;
public Text txtPercent;
Coroutine gaugeUpC;
Coroutine gaugeDownC;
float amount =0;
float targetAmount = 0;
private void Start()
{
}
public void Update()
{
}
public void UpdateGauge()
{
fillImg.fillAmount = amount;
}
public void GaugeUpbyDG()
{
if (targetAmount <= 90)
{
targetAmount += 10;
}
}
public void GaugeUpbyC()
{
if(targetAmount <= 90)
{
StopAllCoroutines();
targetAmount += 10;
gaugeUpC = StartCoroutine(GaugeUpC());
}
}
public void GaugeDownbyDG()
{
if (targetAmount >= 10)
{
targetAmount -= 10;
}
}
public void GaugeDownbyC()
{
if(targetAmount >= 10)
{
StopAllCoroutines();
targetAmount -= 10;
gaugeDownC = StartCoroutine(GaugeDownC());
}
}
IEnumerator GaugeUpC()
{
while (true)
{
if (fillImg.fillAmount * 100 >= targetAmount)
{
fillImg.fillAmount = targetAmount /100;
break;
}
fillImg.fillAmount += 0.011f;
yield return null;
}
}
IEnumerator GaugeDownC()
{
while (true)
{
if (fillImg.fillAmount*100 <= targetAmount)
{
fillImg.fillAmount = targetAmount/100;
break;
}
fillImg.fillAmount -= 0.011f;
yield return null;
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|