예제 #1
0
    private void Update()
    {
        Vector3 mousepos = UtilsClass.GetMouseWorldPosition();

        if (Input.GetMouseButtonDown(0))
        {
            CellGrid.GetValue(mousepos).become_alive();
        }
        if (Input.GetMouseButtonDown(1))
        {
            CellGrid.GetValue(mousepos).die();
        }

        if (Input.GetKeyDown(KeyCode.R) && Time.timeScale == 0f)
        {
            Debug.Log("Neighbors: " + count_alive_neighbors(1, 1));
            Time.timeScale = 0.2f;
        }

        for (int x = 0; x < gridXsize; x++)
        {
            for (int y = 0; y < gridYsize; y++)
            {
                if (CellGrid.GetValue(x, y).isAlive() && !unitytilemap.HasTile(new Vector3Int(x, y, 0)))
                {
                    unitytilemap.SetTile(new Vector3Int(x, y, 0), cellTile);
                }
                else if (!CellGrid.GetValue(x, y).isAlive() && unitytilemap.HasTile(new Vector3Int(x, y, 0)))
                {
                    unitytilemap.SetTile(new Vector3Int(x, y, 0), null);
                }
                else
                {
                }
            }
        }
    }