private void CreateCells() { foreach (Cell cell in Board.Cells) { GameObject newCell = Instantiate(cellPrefab, transform); CellController cellController = newCell.GetComponent <CellController>(); cellController.Cell = cell; } }
public void OnPointerUp(PointerEventData eventData) { foreach (Move move in Piece.Moves) { move.TargetCell.IsHighlighted = false; } //Create a list of Raycast Results List <RaycastResult> results = new List <RaycastResult>(); EventSystem.current.RaycastAll(eventData, results); CellController cellController = null; foreach (var result in results.Where(result => result.gameObject.CompareTag("Cell"))) { cellController = result.gameObject.GetComponent <CellController>(); } Move moveSelected = null; if (cellController != null) { foreach (var move in Piece.Moves.Where(move => cellController.Cell == move.TargetCell)) { moveSelected = move; } } if (moveSelected != null) { selectedMovementEvent.Raise(moveSelected); } else { float size = RectTransform.sizeDelta.x; RectTransform.anchoredPosition = new Vector2(Piece.Position.X * size, Piece.Position.Y * size); } }