void Start() { Settings = FindObjectOfType <CSettingsContainer>(); m_arr_Playground = new CCellBehaviour[Settings.Dimensions.x, Settings.Dimensions.y]; // Fill Playground for (int x = 0; x < m_arr_Playground.GetLength(0); x++) { for (int y = 0; y < m_arr_Playground.GetLength(1); y++) { GameObject go = Instantiate(m_cellPrefab, gameObject.transform); // Position cells go.transform.localPosition = new Vector3(x, -y); CCellBehaviour cellBehaviour = go.GetComponent <CCellBehaviour>(); cellBehaviour.m_ArrPos = new Vector2Int(x, y); // Inform cell about its position m_arr_Playground[x, y] = cellBehaviour; } } // Add neighbors to the cells foreach (CCellBehaviour cell in m_arr_Playground) { AddNeighbors(cell.m_ArrPos.x, cell.m_ArrPos.y, cell); } m_arrFilled = true; // The playgound has been populated Render(); // Startrender of playground }
private void Awake() { m_settings = GetComponentInParent <CPlaygroundBehaviour>().Settings; m_Sprite = GetComponent <SpriteRenderer>(); if (Random.Range(0, 101) <= m_settings.AliveChance) // Randomly select start state by chance { State = ECellState.ALIVE; } else { State = ECellState.DEAD; } }
private CSettingsContainer m_settings; // Settings container holds all rules private void Start() { m_settings = FindObjectOfType <CSettingsContainer>(); }