void Update() { bool leftButton = Input.GetMouseButton(0); bool rightButton = Input.GetMouseButton(1); // Switch between grids when space key is pressed if (Input.GetKeyDown(KeyCode.Space)) { largeSystemActive = !largeSystemActive; } // Respond to mouse event? if (leftButton || rightButton) { // Find mouse position in 3D space Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); TileIndex index = _currentSystem.ClosestTileIndexFromRay(mouseRay); if (leftButton && _lastPainted != index) { // Ignore if this tile was painted last! _lastPainted = index; // Paint with left mouse button _brush.Paint(_currentSystem, index.row, index.column); _currentSystem.RefreshSurroundingTiles(index.row, index.column); } else if (rightButton) { // Ignore last painted state _lastPainted = new TileIndex(-1, -1); // Erase with right mouse button _currentSystem.EraseTile(index.row, index.column); _currentSystem.RefreshSurroundingTiles(index.row, index.column); } } }
public TileIndex ScreenPosToTileIndex(Vector3 pos) { var ray = Camera.main.ScreenPointToRay(pos); return(Floor.ClosestTileIndexFromRay(ray)); }