private void HandleObjectPlacement() { RaycastHit hitInfo; Ray rayHover = _camera.ScreenPointToRay(Input.mousePosition); GridPosition selectedObjectGridPosition; if (Physics.Raycast(rayHover, out hitInfo)) { selectedObjectGridPosition = _grid.GetNearestPointOnGrid(hitInfo.point); _isPositionValid = _grid.CheckIfGridPositionIsValid(selectedObjectGridPosition); _selectedObject.transform.position = selectedObjectGridPosition.Position; _selectedObject.SetVisability(_isPositionValid); if (Input.GetMouseButtonDown(0)) { if (_isPositionValid) { ICommand command = new PlaceLevelObjectCommand(_objectToPlace, selectedObjectGridPosition, _grid); CommandInvoker.AddCommand(command); } } if (Input.GetMouseButtonDown(1)) { LevelObject objectToDelete = hitInfo.collider.transform.GetComponent <LevelObject>(); if (objectToDelete != null) { ICommand command = new DeleteLevelObjectCommand( objectToDelete, _grid.GetNearestPointOnGrid(objectToDelete.transform.position), _grid); CommandInvoker.AddCommand(command); } } } }
private void CreatePlacerPointer() { _selectedObject = Instantiate(_objectToPlace, transform.position, Quaternion.identity, transform); _selectedObject.SetTransparency(true); _selectedObject.GetComponent <Collider>().enabled = false; }