-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomBlocks
117 lines (72 loc) · 1.8 KB
/
RandomBlocks
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using UnityEngine;
using System.Collections;
public class RandomBlocks : MonoBehaviour {
public Transform block;
public int tempJ;
private float nextBlockTime = 0.0f;
public float spawnRate;
public Vector3 tempStartposition;
public ArrayList blockPositionValue = new ArrayList();
// Use this for initialization
void Start () {
// initiate positon and color
tempStartposition = transform.position;
}
// Update is called once per frame
void Update () {
int numberOfBlocks = GameObject.FindGameObjectsWithTag("Block").Length;
if (nextBlockTime < Time.time &&
numberOfBlocks < 40) {
spwanBlock ();
nextBlockTime = Time.time + spawnRate;
}
if (numberOfBlocks > 99) {
foreach(Vector3 i in blockPositionValue)
{
Debug.Log(i);
}
}
}
void spwanBlock(){
//update block start position whith last one of last loop
Vector3 blockPosition = tempStartposition;
int j = 0;
for (int i=0; i < 10; i++) {
j = Random.Range(1,7);
// avoid block at spawned back to same position
while(Mathf.Abs(j-tempJ) == 3)
{
j = Random.Range(1,7);
}
if(Mathf.Abs(j-tempJ) != 3){
switch(j){
case 1:
blockPosition.x ++;
break;
case 2:
blockPosition.y ++;
break;
case 3:
blockPosition.z ++;
break;
case 4:
blockPosition.x --;
break;
case 5:
blockPosition.y --;
break;
case 6:
blockPosition.z --;
break;
}
}
tempJ = j;
block.renderer.material.color = Color.green;
block.name = "block" + i;
blockPositionValue.Add(blockPosition);
Instantiate(block,blockPosition, Quaternion.identity);
//transform.position;
}
tempStartposition = blockPosition;
}
}