Advertisement
Placido_GDD

GameOfLife(cell)

Jan 5th, 2022 (edited)
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Cell : MonoBehaviour
  6. {
  7.     public bool isAlive = false; //tracks if the cell is alive or not
  8.     public int numNeighbors = 0; //tracks number of neighbors beside the cell
  9.     public Color CellAliveColor; //stores RGB color values
  10.     public Color CellDeadColor;  //Stores RGB color values
  11.  
  12.     public void SetAlive(bool alive)
  13.     {
  14.         isAlive = alive;
  15.         if (alive) //if alive is true  enable sprite renderer
  16.         {
  17.            GetComponent<SpriteRenderer>().enabled = true;
  18.            GetComponent<SpriteRenderer>().color = CellAliveColor;
  19.         }
  20.         else
  21.         {
  22.             GetComponent<SpriteRenderer>().enabled = true;
  23.             GetComponent<SpriteRenderer>().color = CellDeadColor;
  24.         }
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement