public GridNode MarkNode() { Vector3 world_pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3 local_pos = transform.InverseTransformPoint(world_pos); // This trick makes a lot of assumptions that the nodes haven't been modified since initialization. int column = Mathf.FloorToInt(local_pos.x / _node_width); int row = Mathf.FloorToInt(-local_pos.y / _node_height); if (row >= 0 && row < _nodes.GetLength(0) && column >= 0 && column < _nodes.GetLength(1)) { GridNode node = _nodes[row, column]; if (node.GetPos() != BoardPosition.Empty) { return(null); } node.SetPos(BoardPosition.Green); return(node); } return(null); }
public void UpdateBoard(GridNode n) { nodes[n.row, n.column].pos = n.GetPos(); }