Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class SpawnManager : MonoBehaviour {
- public GameObject[] animalPrefabs;
- private Vector3 spawnPos = Vector3.zero;
- private float rangeX = 15;
- private float rangeZTop = 15;
- private float rangeZBottom = 2;
- private float zWhenXSpawning = 19f;
- private float xWhenZSpawning = 22f;
- private float startDelay = 2f;
- private float repeatDelay = 0.5f;
- private void Start() {
- InvokeRepeating("SpawnRandomAnimal", startDelay, repeatDelay);
- }
- private void SpawnRandomAnimal() {
- int animalIndex = Random.Range(0, animalPrefabs.Length);
- int direction = Random.Range(1, 4);
- switch(direction) {
- case 1: //Top
- Instantiate(animalPrefabs[animalIndex],
- new Vector3(Random.Range(-rangeX, rangeX), 0f, zWhenXSpawning),
- Quaternion.Euler(0, 180, 0));
- break;
- case 2: //Left
- Instantiate(animalPrefabs[animalIndex],
- new Vector3(-xWhenZSpawning, 0f, Random.Range(rangeZBottom, rangeZTop)),
- Quaternion.Euler(0, 90, 0));
- break;
- case 3: //Right
- Instantiate(animalPrefabs[animalIndex],
- new Vector3(xWhenZSpawning, 0f, Random.Range(rangeZBottom, rangeZTop)),
- Quaternion.Euler(0, -90, 0));
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement