-
Notifications
You must be signed in to change notification settings - Fork 0
/
OrbGeneratorController.cs
97 lines (97 loc) · 3.22 KB
/
OrbGeneratorController.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OrbGeneratorController : MonoBehaviour {
public Pathmaker pathmaker;
public MeshController meshController;
public CoinGeneratorController coinController;
public static OrbGeneratorController instance;
float distance;
List<GameObject> orbs = new List<GameObject> ();
float pointDistance;
int indexs;
public int orbCount = 0;
public int rainbowCycles;
//For Trail change
public bool hitOrb = false;
//For color ring
public bool hitOrb2 = false;
int lastOrbCount;
public bool noneLost = true;
Vector3 scale = new Vector3 (0.3f, 0.3f, 0.3f);
Vector3 zero = new Vector3 (0, 0, 0);
//Out of 1 hundred
private float chanceOfOrb = 2f;
void Start () {
instance = this;
orbCount = 0;
for (int i = 0; i <= 15; i++) {
GameObject orb;
orb = (GameObject) Instantiate (Resources.Load ("Prefab/Objects/ORB"));
orbs.Add (orb);
orb.SetActive (false);
orb.transform.parent = this.transform;
}
distance = Random.Range (5, 10);
}
void Update () {
if (pathmaker.generate4 == true) {
// //print (coinController.orbPoints.Count);
if (pathmaker.checkpoint > 5) {
if (ShouldGenerateOrb ()) {
GenerateOrb (coinController.orbPoints[RandomIndex (coinController.orbPoints.Count - 1)]);
}
}
coinController.orbPoints.Clear ();
pathmaker.generate4 = false;
}
}
void NewDistance () {
distance = Random.Range (15 - pathmaker.checkpoint / 1f, 20 - pathmaker.checkpoint / 1f);
distance = Mathf.Clamp (distance, 6.5f, 20);
}
int RandomIndex (int limit) {
return (Random.Range (0, limit));
}
bool ShouldGenerateOrb () {
if (Random.Range (0, 100) < chanceOfOrb) {
return true;
} else {
return false;
}
}
void GenerateOrb (Vector3 position) {
for (int i = 0; i < orbs.Count - 1; i++) {
if (orbs[i].gameObject.activeInHierarchy == false) {
orbs[i].SetActive (true);
orbs[i].transform.position = new Vector3 (position.x, position.y, 0);
orbs[i].transform.eulerAngles = zero;
orbs[i].transform.localScale = scale;
break;
}
if (i == orbs.Count - 1) {
MakeMoreOrbs ();
}
}
}
int FindClosestPoint (List<Vector3> pois, Vector3 poi) {
pointDistance = 1.4f;
indexs = 0;
for (int i = 0; i < pois.Count - 1; i++) {
if (Vector3.Distance (pois[i], poi) < pointDistance) {
pointDistance = Vector3.Distance (pois[i], poi);
indexs = i;
}
}
return (indexs);
}
void MakeMoreOrbs () {
for (int i = 0; i <= 5; i++) {
GameObject orb;
orb = (GameObject) Instantiate (Resources.Load ("Prefab/Objects/ORB"));
orbs.Add (orb);
orb.SetActive (false);
orb.transform.parent = this.transform;
}
}
}