示例#1
0
    private void HandleMovement()
    {
        if (Input.GetMouseButtonDown(0) && isHeroSelected)
        {
            clickDownPosition = Input.mousePosition;
            hit = DetectHit(clickDownPosition);

            clickDown     = true;
            clickDownTime = Time.time;

            StartCoroutine(RestartClick());
        }
        else if (Input.GetMouseButtonUp(0) && isHeroSelected && clickDown)
        {
            clickUpPosition = Input.mousePosition;
            clickUp         = true;

            StopCoroutine(RestartClick());
        }

        if (clickDown && clickUp && clickDownPosition == clickUpPosition)
        {
            Vector2 clickedPos = Input.mousePosition;
            if (tilemapHandler.IsTile(Camera.main.ScreenToWorldPoint(clickedPos)))
            {
                Vector3Int gridPos     = tilemapHandler.ScreenToCellPosition(clickedPos);
                Node       clickedCell = tilemapHandler.GetTile(gridPos);
                if (clickedCell.tile.isWalkable)
                {
                    pathFinding.startPos = tilemapHandler.WorldToCellPosition(currentPosition);
                    pathFinding.goalPos  = clickedCell.position;
                    pathFinding.FindPath();

                    heroPositionAndState.Position     = targetPosition;
                    heroPositionAndState.IsAtPosition = false;
                    placeSelectEvent.Raise(heroPositionAndState);
                }
            }

            clickUp       = false;
            clickDown     = false;
            clickDownTime = 0f;
        }
    }