using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MonsterInstantiate : MonoBehaviour
{
ย  ย  public GameObject monster1;
ย  ย  WaitForSeconds RespawnTime = new WaitForSeconds(5f);
ย  ย  bool isDelay = true;
ย  ย 


ย  ย  // Start is called before the first frame update
ย  ย  void Start()
ย  ย  {
ย  ย  ย  ย  Spawn();

ย  ย  }

ย  ย  // Update is called once per frame
ย  ย  void Update()
ย  ย  {
ย  ย  ย  ย  var monsterobjs = FindObjectsOfType<MonsterMoving>();
ย  ย  ย  ย 
ย  ย  ย  ย  if (monsterobjs.Length == 0)
ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  StartCoroutine(spawn());
ย  ย  ย  ย  ย  ย  if (isDelay == false)
ย  ย  ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  ย  ย  Spawn();
ย  ย  ย  ย  ย  ย  ย  ย  isDelay = true;
ย  ย  ย  ย  ย  ย  }
ย  ย  ย  ย  }
ย  ย  }

ย  ย  IEnumerator spawn()
ย  ย  {
ย  ย  ย  ย  yield return RespawnTime;
ย  ย  ย  ย  isDelay = false;

ย  ย  }
ย  ย  void Spawn()
ย  ย  {
ย  ย  ย  ย  Instantiate(monster1, new Vector3(Random.Range(0, 10), -4, 0), Quaternion.identity);
ย  ย  ย  ย  Instantiate(monster1, new Vector3(Random.Range(0, 10), -4, 0), Quaternion.identity);
ย  ย  ย  ย  Instantiate(monster1, new Vector3(Random.Range(0, 10), -4, 0), Quaternion.identity);

ย  ย  }
}

์ •ํ™•ํžˆ๋Š” ์ฒ˜์Œ ๋‚˜์˜จ ๋ชฌ์Šคํ„ฐ3๋ช… ์ฃฝ์ด๋ฉด 5์ดˆ๊ธฐ๋‹ค๋ฆฌ๊ณ  ์ƒ์„ฑ๋˜๋Š”๋ฐ
๋‘๋ฒˆ์งธ๋ถ€ํ„ฐ ์ƒ์„ฑ๋œ ๋ชฌ์Šคํ„ฐ3๋ช… ์ฃฝ์ด๋ฉด ๋”œ๋ ˆ์ด์—†์ด ๋ฐ”๋กœ ์ƒ์„ฑ๋ผ์š” ์™œ์ด๋Ÿฐ๊ฑฐ์ฃ