Coroutine
2020. 5. 26. 10:03
728x90
>>> 진입지점이 여러개
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UITestCoroutine : MonoBehaviour
{
public Image dim;
void Start()
{
//this.Fade();
this.StartCoroutine(this.FadeImpl());
}
void Update()
{
}
void Fade()
{
for (float f = 1f; f >= 0; f -= 0.1f)
{
Color c = dim.color; // renderer.material.color;
Debug.Log(f);
c.a = f;
dim.color = c;
//renderer.material.color = c;
}
}
IEnumerator FadeImpl()
{
for (float f = 1f; f >= 0; f -= 0.1f)
{
Color c = dim.color;
Debug.Log(f);
c.a = f;
dim.color = c;
yield return null; // 다음 프레임
}
}
}
|
cs |
>>> 0.1초 지연
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
|
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class UITestCoroutine : MonoBehaviour
{
public Image dim;
void Start()
{
//this.Fade();
this.StartCoroutine(this.FadeImpl());
}
void Update()
{
}
void Fade()
{
for (float f = 1f; f >= 0; f -= 0.1f)
{
Color c = dim.color; // renderer.material.color;
Debug.Log(f);
c.a = f;
dim.color = c;
//renderer.material.color = c;
}
}
IEnumerator FadeImpl()
{
for (float f = 1f; f >= 0; f -= 0.1f)
{
Color c = dim.color;
c.a = f;
dim.color = c;
yield return new WaitForSeconds(.1f); // 0.1초 지연
}
}
}
|
cs |
728x90
'Unity > Study' 카테고리의 다른 글
Shader B/W, Bright and Darkness (0) | 2020.06.24 |
---|---|
2D Character Move with mousemotion (0) | 2020.05.27 |
DrawWireArc(Attack arange) (0) | 2020.05.25 |
DOTween(캐릭터 공격력 효과) (0) | 2020.05.25 |
Box Colider (0) | 2020.05.25 |