Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayFieldBehaviour : MonoBehaviour
  6. {
  7.   // public GameObject cellType0; // because zero means "null"
  8.   public GameObject cellType1;
  9.   public GameObject cellType2;
  10.   public GameObject cellType3;
  11.   public GameObject cellType4;
  12.   GameObject[] CellTypes;
  13.   GameObject[,] FieldMap;
  14.  
  15.   void Start()
  16.   {
  17.     CellTypes = new GameObject[5];
  18.     CellTypes[1] = cellType1;
  19.     CellTypes[2] = cellType2;
  20.     CellTypes[3] = cellType3;
  21.     CellTypes[4] = cellType4;
  22.     FieldMap = new GameObject[4, 5];
  23.     //initial codes of cells
  24.     int[,] FieldCode = new int[4, 5] {
  25.       { 2, 1, 2, 3, 2 },
  26.       { 1, 1, 3, 1, 2 },
  27.       { 3, 3, 2, 1, 2 },
  28.       { 2, 1, 3, 1, 2 }
  29.     };
  30.  
  31.     FillField(FieldMap, FieldCode);
  32.   }
  33.  
  34.   void Update()
  35.   {
  36.  
  37.   }
  38.  
  39.   void FillField(GameObject[,] FieldToFill, int[,] CodeArray )
  40.   {
  41.     int FirstSize = FieldToFill.GetLength(0);
  42.     int SecondSize = FieldToFill.GetLength(1);
  43.     for (int i = 0; i < FirstSize; i++)
  44.     {
  45.       for (int k = 0; k < SecondSize; k++)
  46.       {
  47.         FieldToFill[i, k] = Instantiate(CellTypes[CodeArray[i,k]]);
  48.         FieldToFill[i, k].transform.position = new Vector2(k * 4, i * -4);
  49.       }
  50.     }
  51.   }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement