SHOW:
|
|
- or go back to the newest paste.
1 | using System.Collections; | |
2 | using System.Collections.Generic; | |
3 | using Unity.VisualScripting; | |
4 | using UnityEngine; | |
5 | ||
6 | public class BricksGenerator : MonoBehaviour | |
7 | { | |
8 | ||
9 | public int[,] bricksArray = new int[,] { | |
10 | {0,0,0,0,2,0,0,0,0}, | |
11 | {0,0,0,1,2,1,0,0,0}, | |
12 | {0,0,2,2,2,2,2,0,0}, | |
13 | {0,1,1,1,2,1,1,1,0}, | |
14 | {0,0,0,0,2,0,0,0,0}, | |
15 | ||
16 | }; | |
17 | ||
18 | public int[,] bricksArray2 = new int[,] { | |
19 | {0,0,0,0,2,0,0,0,0}, | |
20 | {0,0,0,1,2,1,0,0,0}, | |
21 | {0,0,2,2,2,2,2,0,0}, | |
22 | {0,1,1,1,2,1,1,1,0}, | |
23 | {0,0,0,0,2,0,0,0,0} | |
24 | }; | |
25 | ||
26 | public int[,] bricksArray3 = new int[,] { | |
27 | {0,0,3,0,0}, | |
28 | {0,0,3,0,0}, | |
29 | {0,2,3,2,2}, | |
30 | {1,1,3,1,1}, | |
31 | {0,2,3,2,0} | |
32 | }; | |
33 | ||
34 | List<int[,]> levels = new List<int[,]>(); | |
35 | public GameObject brick; | |
36 | ||
37 | void Start() | |
38 | { | |
39 | levels.Add(bricksArray); | |
40 | levels.Add(bricksArray2); | |
41 | levels.Add(bricksArray3); | |
42 | GameManager.instance.maxLevel = levels.Count; | |
43 | StartLevel(1); | |
44 | ||
45 | GenerateBricks(bricksArray2); | |
46 | } | |
47 | ||
48 | public void GenerateBricks(int[,] array) | |
49 | { | |
50 | for(int i = 0; i < array.GetLength(0); i++) | |
51 | { | |
52 | for(int j = 0; j < array.GetLength(1); j++) | |
53 | { | |
54 | if (array[i, j] == 0) continue; | |
55 | Vector3 pos = new Vector3((-(array.GetLength(1)/2) + (j *1)),(4-i*0.3f),0); | |
56 | GameObject b = Instantiate(brick,pos, Quaternion.identity); | |
57 | b.transform.parent = gameObject.transform; | |
58 | b.GetComponent<BricksScript>().SetBrick(array[i,j]); | |
59 | } | |
60 | } | |
61 | GameManager.instance.bricks.AddRange(GameObject.FindGameObjectsWithTag("Brick")); | |
62 | } | |
63 | ||
64 | public void StartLevel(int number) | |
65 | { | |
66 | GameManager.instance.bricks.Clear(); | |
67 | GenerateBricks(levels[number-1]); | |
68 | GameManager.instance.UpdateUI(); | |
69 | ||
70 | } | |
71 | } | |
72 |