using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RandomPoint : MonoBehaviour
{
// ์๊ฐ์ ๋ด๋นํ ๋ณ์๋ฅผ ํ๋ ๋ง๋ค์ด์ค๋ค.
public float currTime;
public GameObject randomSpawn;
// ๋ฐ๋ณต๋๋ ์์
์ด๋ฏ๋ก ์
๋ฐ์ดํธ ํจ์ ์์์ ์ฝ๋๋ฅผ ์
๋ ฅํ๋ค.
public void Update()
{
// ์๊ฐ์ด ํ๋ฅด๊ฒ ๋ง๋ค์ด์ค๋ค.
currTime += Time.deltaTime;
// ์ค๋ธ์ ํธ๋ฅผ ๋ช์ด๋ง๋ค ์์ฑํ ๊ฒ์ธ์ง ์กฐ๊ฑด๋ฌธ์ผ๋ก ๋ง๋ ๋ค. ์ฌ๊ธฐ์๋ 10์ด๋ก ํ๋ค.
if (currTime > 1)
{
// x,y,z ์ขํ๊ฐ์ ๊ฐ๊ฐ ๋ค๋ฅธ ๋ฒ์์์ ๋๋คํ๊ฒ ์ ํด์ง๋๋ก ๋ง๋ค์๋ค.
float newX = Random.Range(-10f, 10f), newZ = Random.Range(-100f, 100f);
// ์์ฑํ ์ค๋ธ์ ํธ๋ฅผ ๋ถ๋ฌ์จ๋ค.
//Instantiate(randomSpawn);
Instantiate(randomSpawn);
// ๋ถ๋ฌ์จ ์ค๋ธ์ ํธ๋ฅผ ๋๋คํ๊ฒ ์์ฑํ ์ขํ๊ฐ์ผ๋ก ์์น๋ฅผ ์ฎ๊ธด๋ค.
randomSpawn.transform.position = new Vector3(newX, transform.position.y, newZ);
// ์๊ฐ์ 0์ผ๋ก ๋๋๋ ค์ฃผ๋ฉด, 10์ด๋ง๋ค ๋ฐ๋ณต๋๋ค.
currTime = 0;
}
}
}