-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpawnObstacles.cs
More file actions
29 lines (26 loc) · 917 Bytes
/
SpawnObstacles.cs
File metadata and controls
29 lines (26 loc) · 917 Bytes
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnObstacles : MonoBehaviour
{
[SerializeField] private GameObject[] obstacles;
[SerializeField] private float intialSpawnRate = 2f;
[SerializeField] private float currentSpawnRate;
[SerializeField] private float minSpawnRate = 0.25f;
[SerializeField] private float spawnDecreaseRate = 0.5f;
void Start()
{
currentSpawnRate = intialSpawnRate;
InvokeRepeating("Spawn", 0f, currentSpawnRate);
}
void Update()
{
currentSpawnRate -= spawnDecreaseRate*Time.deltaTime;
currentSpawnRate = Mathf.Max(currentSpawnRate,minSpawnRate);
}
void Spawn()
{
GameObject obstaclePrefab = obstacles[Random.Range(0, obstacles.Length)];
Instantiate(obstaclePrefab, transform.position, Quaternion.identity);
}
}