-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpawnManager_2.cs
More file actions
40 lines (31 loc) · 1.11 KB
/
SpawnManager_2.cs
File metadata and controls
40 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using UnityEngine;
using Random = UnityEngine.Random;
public class SpawnManager_2 : MonoBehaviour
{
public GameObject[] animalPrefabs;
private float startTime = 2;
void SpawnRandomAnimals()
{
int animalIndex = UnityEngine.Random.Range(0, animalPrefabs.Length);
int positionX = UnityEngine.Random.Range(-20, 20);
Instantiate(animalPrefabs[animalIndex], new Vector3(positionX, 0, 20),
animalPrefabs[animalIndex].transform.rotation);
}
void SpawnAnimalsFromSide()
{
int animalIndex = UnityEngine.Random.Range(0, animalPrefabs.Length);
float randomZ = UnityEngine.Random.Range(2, 15);
Vector3 spawnPos = new Vector3(-25.0f, 0, randomZ);
Quaternion spawnRot = Quaternion.Euler(0, 90, 0);
Instantiate(animalPrefabs[animalIndex], spawnPos, spawnRot);
}
void Start()
{
InvokeRepeating("SpawnRandomAnimals", startTime, Random.Range(2,6));
InvokeRepeating("SpawnAnimalsFromSide", startTime+2, Random.Range(3,7));
}
void Update()
{
}
}