Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayFieldBehaviour : MonoBehaviour
- {
- // public GameObject cellType0; // because zero means "null"
- public GameObject cellType1;
- public GameObject cellType2;
- public GameObject cellType3;
- public GameObject cellType4;
- GameObject[] CellTypes;
- GameObject[,] FieldMap;
- void Start()
- {
- CellTypes = new GameObject[5];
- CellTypes[1] = cellType1;
- CellTypes[2] = cellType2;
- CellTypes[3] = cellType3;
- CellTypes[4] = cellType4;
- FieldMap = new GameObject[4, 5];
- //initial codes of cells
- int[,] FieldCode = new int[4, 5] {
- { 2, 1, 2, 3, 2 },
- { 1, 1, 3, 1, 2 },
- { 3, 3, 2, 1, 2 },
- { 2, 1, 3, 1, 2 }
- };
- FillField(FieldMap, FieldCode);
- }
- void Update()
- {
- }
- void FillField(GameObject[,] FieldToFill, int[,] CodeArray )
- {
- int FirstSize = FieldToFill.GetLength(0);
- int SecondSize = FieldToFill.GetLength(1);
- for (int i = 0; i < FirstSize; i++)
- {
- for (int k = 0; k < SecondSize; k++)
- {
- FieldToFill[i, k] = Instantiate(CellTypes[CodeArray[i,k]]);
- FieldToFill[i, k].transform.position = new Vector2(k * 4, i * -4);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement