-
[3D] Random Range SpawnUnity(유니티) 2022. 7. 18. 14:37
일정한 구간을 정해두고 구간 내에서 오브젝트를 스폰함
InvokeRepeating(string methodName, float time, float repeatRate);
using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpawnManager : MonoBehaviour { public GameObject[] animalPrefabs; private float spawnRangeX = 20; private float spawnPosZ = 20; private float startDelay = 2; private float spawnInterval = 1.5f; // Start is called before the first frame update void Start() { InvokeRepeating("SpawnRandomAnimal", startDelay, spawnInterval); } void SpawnRandomAnimal() { int animalIndex = Random.Range(0, animalPrefabs.Length); Vector3 spawnPos = new Vector3(Random.Range(-spawnRangeX, spawnRangeX), 0, spawnPosZ); Instantiate(animalPrefabs[animalIndex], spawnPos, animalPrefabs[animalIndex].transform.rotation); } }
'Unity(유니티)' 카테고리의 다른 글
[UI] 이미지를 이용한 페이드 아웃 (0) 2022.08.31 [3D]Destroy out of Bounds (0) 2022.07.18 [3D] 오브젝트 회전 (Mathf.PI, Mathf.Cos, Mathf.Sin, Quaternion) (0) 2022.07.08 WebGL publishing (0) 2022.05.13 Project Design Document (0) 2022.05.13