void Update() { // Update grid lines and cell size if (PreviousCellSize != CellSize || PreviousLineColor != LineColor || PreviousLineWidth != LineWidth) { RefreshGrid(); } // Convert mouse position to Grid Coordinates Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); int x = (int)((pos.x - this.transform.position.x) / (CellSize + LineWidth)); int y = -(int)((pos.y - this.transform.position.y) / (CellSize + LineWidth)); // Check if we are filling or erasing walls if (Input.GetMouseButtonDown(0)) { if ((x > 0 && x < Cells.GetLength(0)) && (y > 0 && y < Cells.GetLength(1))) { if (Cells [x, y].Type == CellType.Blank) { Fill = true; } else { Fill = false; } } } // Left click draws/erases walls if (Input.GetMouseButton(0)) { if (x != 0 && y != 0 && x != Width - 1 && y != Height - 1) { if ((x > 0 && x < Cells.GetLength(0)) && (y > 0 && y < Cells.GetLength(1))) { if (Fill) { Cells [x, y].SetType(CellType.Solid); } else { Cells [x, y].SetType(CellType.Blank); } } } } // Right click places liquid if (Input.GetMouseButton(1)) { if ((x > 0 && x < Cells.GetLength(0)) && (y > 0 && y < Cells.GetLength(1))) { Cells [x, y].AddLiquid(5); } } // Run our liquid simulation LiquidSimulator.Simulate(ref Cells); }