Last active
August 29, 2015 14:18
-
-
Save tsubaki/596ebb4566bd21b55e62 to your computer and use it in GitHub Desktop.
コルーチンの再開
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class CoroutineSample1 : MonoBehaviour | |
{ | |
[SerializeField] | |
UnityEngine.UI.Text text; | |
IEnumerator coroutineMethod; | |
void Start() | |
{ | |
// IEnumeratorを取得する | |
coroutineMethod = ChangeColorCoroutine(); | |
} | |
void OnMouseDown() | |
{ | |
// コルーチンをIEnumeratorの位置から開始(再開) | |
StartCoroutine(coroutineMethod); | |
} | |
void OnMouseUp() | |
{ | |
// コルーチンを停止 | |
StopCoroutine(coroutineMethod); | |
} | |
IEnumerator ChangeColorCoroutine() | |
{ | |
float clickTime = 0; | |
// コルーチン進行中は数値を増加させる | |
while( clickTime < 3 ){ | |
clickTime += Time.deltaTime; | |
text.text = clickTime.ToString("0.000"); | |
yield return null; | |
} | |
text.text = "finished"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment