Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/596ebb4566bd21b55e62 to your computer and use it in GitHub Desktop.
Save tsubaki/596ebb4566bd21b55e62 to your computer and use it in GitHub Desktop.
コルーチンの再開
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