-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpawnObject.cs
More file actions
36 lines (30 loc) · 1.22 KB
/
Copy pathSpawnObject.cs
File metadata and controls
36 lines (30 loc) · 1.22 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnObject : MonoBehaviour
{
//[NOTES]The level generation properties are all defined here and sorted so they they appear nicely in the unity editor
//[NOTES]Note the use of serialized private fields, to allow for access and editing in the editor window for test purposes, while maintaining encapsulation of the variables.
[SerializeField]
private GameObject[] objects;
[Range(1f, 100f)]
[SerializeField]
private float spawnRate;
private void Start()
{
RandomizeSpawn();
}
//[NOTES]If the spawn node succeeds, a random object will be spawned
//[NOTES]This is used for random terrain as well as random items & pickups.
//[NOTES]Specify the object list in the inspector at the spawn node
private void RandomizeSpawn()
{
int roll = Random.Range(1, 101);
if (roll < spawnRate)
{
int rand = Random.Range(0, objects.Length);
GameObject newPickup = Instantiate(objects[rand], transform.position, Quaternion.identity);
newPickup.transform.parent = this.gameObject.transform;
}
}
}