コルーチン
コルーチン
using System;
using System.Collections;
using UnityEngine;
public static class コルーチン
{
public static IEnumerator 待つ(float 秒数, Action 処理)
{
yield return new WaitForSeconds(秒数);
処理?.Invoke();
}
public static IEnumerator 繰り返す(float 間隔秒, Action 処理)
{
while (true)
{
yield return new WaitForSeconds(間隔秒);
処理?.Invoke();
}
}
}
使い方
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
let 秒数=0;
秒数+=2;
StartCoroutine(待つ(秒数, () => {
Debug.Log("攻撃! ダメージ:10");
}));
秒数+=3;
StartCoroutine(待つ(秒数, () => {
Debug.Log("攻撃! ダメージ:10");
}));
}
}

