-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generator.cs
75 lines (51 loc) · 2.32 KB
/
Generator.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
using UnityEngine;
using System.Collections;
public class Generator : MonoBehaviour {
public GameObject thePlatform;
public Transform generationPoint;
private float distanceBetween;
public float distanceBetweenMin;
public float distanceBetweenMax;
public ObjectPooler[] theObjectPools;
private float platformWidth;
private int platformSelector;
private float[] platformWidths;
private float minHight;
public Transform maxHeightPoint;
private float maxHeight;
public float maxHeightChange;
private float heightChange;
void Start () {
minHight = transform.position.y;
maxHeight = maxHeightPoint.position.y;
platformWidths = new float[theObjectPools.Length];
for(int i=0;i<theObjectPools.Length;i++)
{
platformWidths[i] = theObjectPools[i].pooledObject.GetComponent<BoxCollider2D>().size.x;
}
}
void Update () {
if (transform.position.x < generationPoint.position.x)
{
distanceBetween = Random.Range(distanceBetweenMin, distanceBetweenMax);
platformSelector = Random.Range(0, theObjectPools.Length);
heightChange = transform.position.y + Random.Range(maxHeightChange, -maxHeightChange);
if (heightChange > maxHeight)//tezi redove ne sa zaduljitelni zashtoto camera sledva player
{ heightChange = maxHeight; }
else if(heightChange<minHight)
{ heightChange = minHight; }
transform.position = new Vector3(transform.position.x + (platformWidths[platformSelector]/2)+ distanceBetween , heightChange, transform.position.z);
GameObject newPlatform = theObjectPools[platformSelector].GetPooledObject();
newPlatform.transform.position = transform.position;
//newPlatform.transform.rotation = transform.rotation;
if(newPlatform.CompareTag("FallingPlatform"))
{
newPlatform.GetComponent<Rigidbody2D>().isKinematic= true;
newPlatform.GetComponent<FallingPlatform>().contact = false;
//newPlatform.GetComponent<Collider2D>().isTrigger=false;
}
newPlatform.SetActive(true);
transform.position = new Vector3(transform.position.x + (platformWidths[platformSelector] / 2), transform.position.y, transform.position.z);
}
}
}