![업로드중..]()
public class PlatformSpawner : MonoBehaviour
{
public GameObject platform;
public Transform lastPlatform;
private Vector3 lastPosition;
private Vector3 newPos;
private float platformSize = 2f;
private bool stop;
private void Start()
{
lastPosition = lastPlatform.position;
StartCoroutine(SpawnPlatforms());
}
private void Update()
{
}
IEnumerator SpawnPlatforms()
{
while (!stop)
{
GeneratePoition();
Instantiate(platform, newPos, Quaternion.identity);
lastPosition = newPos;
yield return new WaitForSeconds(0.1f);
}
}
private void GeneratePoition()
{
newPos = lastPosition;
int rand = Random.Range(0, 2);
if(rand > 0)
{
newPos.x += platformSize;
}
else
{
newPos.z += platformSize;
}
}
}