Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Simulate : MonoBehaviour {
- bool simulate = true;
- int size = 100;
- float diameter;
- public CellGO[] cells = new CellGO[100];
- // Use this for initialization
- void Start ()
- {
- diameter = Mathf.Sqrt(size);
- int i = 0;
- while (i < size)
- {
- GameObject go = Instantiate(GameObject.Find("Cell"), new Vector3(cells[i].x, 0, cells[i].y), Quaternion.identity) as GameObject;
- cells[i] = go.AddComponent<>
- cells[i].alive = 1;
- cells[i].x = i / 10;
- cells[i].y = i % 10;
- cells[i].go = go;
- print(("Made cell " + i + " with location x" + cells[i].x + " and y "+cells[i].y));
- i += 1;
- }
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown("g"))
- {
- simulate = !simulate;
- }
- if (simulate)
- {
- int i = 0;
- while (i < size)
- {
- int count = 0;
- try
- {
- count += cells[i + 1].alive;
- count += cells[i - 1].alive;
- count += cells[i + size].alive;
- count += cells[i - size].alive;
- }
- catch { }
- cells[i].near = count;
- if (cells[i].alive == 1)
- {
- if (count == 0 || count == 1)
- {
- cells[i].changeAlive(0);
- }
- if (count > 3)
- {
- cells[i].changeAlive(0);
- }
- }
- else
- {
- if (count == 3)
- {
- cells[i].changeAlive(1);
- }
- }
- i += 1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment