-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatformGenerator.cs
More file actions
71 lines (51 loc) · 1.97 KB
/
platformGenerator.cs
File metadata and controls
71 lines (51 loc) · 1.97 KB
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
using System;
using UnityEngine;
public class platformGenerator : MonoBehaviour
{
public GameObject thePlatform;
public Transform generationPoint;
public float distanceBetween;
private float platformWidth;
public float distanceBetweenMin;
public float distanceBetweenMax;
private float[] platformWidths;
public GameObject[] thePlatforms;
private int platformSelector;
private float minHeight;
public Transform maxHeihtPoint;
private float maxHeight;
public float maxHeightChange;
private float heightChange;
// Use this for initialization
void Start()
{
// platformWidth = thePlatform.GetComponent<BoxCollider2D>().size.x;
platformWidths = new float[thePlatforms.Length];
for(int i =0; i<thePlatforms.Length; i++)
{
platformWidths[i] = thePlatforms[i].GetComponent<BoxCollider2D>().size.x;
}
minHeight = transform.position.y;
maxHeight = maxHeihtPoint.position.y;
}
// Update is called once per frame
void Update()
{
if (transform.position.x < generationPoint.position.x)
{
distanceBetween = UnityEngine.Random.Range(distanceBetweenMin, distanceBetweenMax);
platformSelector = UnityEngine.Random.Range(0, thePlatforms.Length);
heightChange = transform.position.y + UnityEngine.Random.Range(maxHeightChange, -maxHeightChange);
if (heightChange > maxHeight)
{
heightChange = maxHeight;
}
else if (heightChange < minHeight)
{
heightChange = minHeight;
}
transform.position = new Vector3(transform.position.x + platformWidths[platformSelector] + distanceBetween,heightChange, transform.position.z);
Instantiate(thePlatforms[platformSelector], transform.position, transform.rotation);
}
}
}