-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoinManager.cs
47 lines (38 loc) · 1.19 KB
/
CoinManager.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
using UnityEngine;
public class CoinManager : MonoBehaviour {
GameObject[] coins;
Rigidbody2D playerRB;
PlayerController playerInfo;
int amtOfCoins;
float vertExtent;
public float height;
public float coinVerticalDistance;
void Start () {
coins = GameObject.FindGameObjectsWithTag("Coin");
amtOfCoins = coins.Length;
vertExtent = Camera.main.orthographicSize;
playerRB = GameObject.Find("Player").GetComponent<Rigidbody2D>();
playerInfo = playerRB.GetComponent<PlayerController>();
for (int i = 0; i < amtOfCoins; i++)
{
RepositionCoin(i);
}
}
void Update () {
if (playerInfo.grounded == true)
{
for (int i = 0; i < amtOfCoins; i++)
{
if (coins[i].transform.position.y < Camera.main.transform.position.y - vertExtent)
{
RepositionCoin(i);
}
}
}
}
void RepositionCoin (int i)
{
coins[i].transform.position = new Vector2(Random.Range(-2.25f, 2.25f), height);
height += coinVerticalDistance;
}
}