-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoinSpawner.cs
52 lines (32 loc) · 1.16 KB
/
CoinSpawner.cs
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
41
42
43
44
45
46
47
48
49
50
51
52
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoinSpawner : MonoBehaviour
{
[SerializeField]
private float timeBetweenSpawn;
[SerializeField]
private GameObject prefab;
private float timeToNextSpawn;
// Start is called before the first frame update
void Start()
{
timeToNextSpawn = timeBetweenSpawn;
}
// Update is called once per frame
void Update()
{
//very clever way to program in time using the update method
timeToNextSpawn = timeToNextSpawn - Time.deltaTime; //subtrtact the time every frame from the time we inputed in or spawn till its 0 again
if (timeToNextSpawn <= 0.0f)
{
Spawn();
timeToNextSpawn = timeBetweenSpawn; //we redo the time to next spawn so it is eqaul agian to the next one
}
}
void Spawn()
{
for (int i=0; i<30; i++)
Instantiate(prefab, new Vector2(-10 + 0.7f * i, 15), Quaternion.identity); //this will basically spawn the coins in a row using the variable i as a way to consitantly increase the x access spawning point
}
}