Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (Input.GetMouseButtonDown(0))
        {
            if (grid.WorldToCell(mousePos).Equals(grid.WorldToCell(transform.position)))
            {
                // Reset
                selected = true;
                path.Clear();
                path = new Path(grid.WorldToCell(mousePos), pathTilemap, pathTile);
            }
        }

        if (Input.GetMouseButtonUp(0) && selected)
        {
            selected = false;
        }

        if (Input.GetMouseButton(0) && selected)
        {
            // Register path
            Vector3Int mouseCell = grid.WorldToCell(mousePos);
            if (!mouseCell.Equals(lastMouseCell) && boundsTilemap.cellBounds.Contains(mouseCell))
            {
                path.AddDestination(mouseCell);
                lastMouseCell = mouseCell;
            }
        }

        positions = path.PathPositions();
    }