敵がFireBallを発射する2(コルーチンで実行)



コルーチンで発射を実行
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// FireBallの発射をコルーチンで実行
public class EnemyShot2 : MonoBehaviour
{
public GameObject shotPrefab;
public GameObject shotPoint;
public float interval;
void Start()
{
StartCoroutine(Shot());
}
private IEnumerator Shot()
{
yield return new WaitForSeconds(2f);
while (true)
{
// 1タームに何回繰り返すか?
for (int i = 0; i < 3; i++)
{
Instantiate(shotPrefab, shotPoint.transform.position, Quaternion.identity);
// 何秒間隔で発射するか?
yield return new WaitForSeconds(interval);
}
// 1タームが終了したら3秒間休む
yield return new WaitForSeconds(3f);
}
}
}


【2022版】ActionGame2D(全33回)
他のコースを見る


コルーチンで発射を実行
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// FireBallの発射をコルーチンで実行
public class EnemyShot2 : MonoBehaviour
{
public GameObject shotPrefab;
public GameObject shotPoint;
public float interval;
void Start()
{
StartCoroutine(Shot());
}
private IEnumerator Shot()
{
yield return new WaitForSeconds(2f);
while (true)
{
// 1タームに何回繰り返すか?
for (int i = 0; i < 3; i++)
{
Instantiate(shotPrefab, shotPoint.transform.position, Quaternion.identity);
// 何秒間隔で発射するか?
yield return new WaitForSeconds(interval);
}
// 1タームが終了したら3秒間休む
yield return new WaitForSeconds(3f);
}
}
}


敵がFireBallを発射する2(コルーチンで実行)