Advertisement
Placido_GDD

GameManagerGoL

Jan 5th, 2022
575
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Game_Manager : MonoBehaviour
  6. {
  7.     public GameObject gameManager; //to be instantiated. Pass values livingCells,speed and color of square here
  8.     public int livingCells; //must be greater than zero but less than or equal 100
  9.     public float speed;
  10.     public Color CellColorAlive;
  11.     public Color CellColorDead;
  12.     //
  13.     private List<GameObject> gridSquares = new List<GameObject>();
  14.     private GameObject square;
  15.     private GameObject grid_Manager;
  16.     public bool Reset;
  17.     public bool SpawnNewGrid;
  18.     // Start is called before the first frame update
  19.     void Start()
  20.     {
  21.  
  22.     }
  23.  
  24.     // Update is called once per frame
  25.     void Update()
  26.     {
  27.         ResetGrid();        
  28.     }
  29.  
  30.     public void ToggleReset()
  31.     {
  32.         Reset = !Reset;
  33.     }
  34.     void CreateNewGrid()
  35.     {
  36.             grid_Manager = Instantiate(gameManager, new Vector3(0, 0, 0), Quaternion.identity);
  37.             grid_Manager.GetComponent<Game>().CellAliveColorVal = CellColorAlive;
  38.             grid_Manager.GetComponent<Game>().CellDeadColorVal = CellColorDead;
  39.     }
  40.     void ResetGrid()
  41.     {
  42.         if (Reset == true)
  43.         {
  44.             grid_Manager = GameObject.FindGameObjectWithTag("Manager");
  45.             gridSquares.AddRange(GameObject.FindGameObjectsWithTag("Square"));
  46.             Destroy(grid_Manager);
  47.             foreach (GameObject square in gridSquares)
  48.             {
  49.                 Destroy(square);
  50.             }
  51.             gridSquares.Clear();
  52.             CreateNewGrid();
  53.             Reset = false;
  54.         }
  55.     }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement