-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemSetup.cs
More file actions
37 lines (31 loc) · 1.19 KB
/
Copy pathItemSetup.cs
File metadata and controls
37 lines (31 loc) · 1.19 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
using UnityEngine;
public class ItemSetup : MonoBehaviour
{
private Cell[,] cellArray;
private FieldItem[,] itemsArray;
private int rows, cols;
public FieldItem[] itemPrefabs;
private void OnEnable() => Cell.MakeNewItem += SetItemsOfFirstRow;
private void OnDisable() => Cell.MakeNewItem -= SetItemsOfFirstRow;
private void Start()
{
cellArray = Cell_Setup.cellArray;
rows = cellArray.GetLength(0);
cols = cellArray.GetLength(1);
itemsArray = new FieldItem[rows, cols];
for (int i = 0; i < cols; i++)
{
Cell cellofFirstRow = cellArray[rows-1,i];
SetItemsOfFirstRow(cellofFirstRow);
itemsArray[rows-1, i] = cellofFirstRow.cellItem;
}
}
private void SetItemsOfFirstRow(Cell cellOfFirstRow)
{
int randomItem = Random.Range(0, itemPrefabs.Length);
FieldItem newItem = Instantiate(itemPrefabs[randomItem], cellOfFirstRow.transform.position, Quaternion.identity);
newItem.itemCell = cellOfFirstRow;
cellOfFirstRow.cellItem = newItem;
cellOfFirstRow.isEmpty = false;
}
}