コード例 #1
0
    private void MovePlayer()
    {
        actionCompleted = false;
        if (selectedWaypoint.walkable)
        {
            if (Math.Abs(selectedWaypoint.GetGridPos().x - selectedPlayer.PlayerGridPos().x) < selectedPlayer.GetMoveRange())
            {
                if (Math.Abs(selectedWaypoint.GetGridPos().y - selectedPlayer.PlayerGridPos().y) < selectedPlayer.GetMoveRange())
                {
                    var path = pathfinder.GetPath(selectedPlayer.wayPointCovering, selectedWaypoint);
                    if (selectedPlayer.HasPuck)
                    {
                        puck.FollowPlayer();
                    }
                    selectedPlayer.SetMovePath(path);

                    selectedPlayer.hasCompletedAction = true;
                }
                else
                {
                    gameState = GameState.pickWaypoint;
                    StartCoroutine(textUpdate.UpdateSecondaryText(WaitTime, "Waypoint out of range, select again"));
                    return;
                }
            }
            else
            {
                gameState = GameState.pickWaypoint;
                StartCoroutine(textUpdate.UpdateSecondaryText(WaitTime, "Waypoint out of range, select again"));
                return;
            }
        }
        else
        {
            StartCoroutine(textUpdate.UpdateSecondaryText(WaitTime, "Can't move to selected location, try again"));
            selectedPlayer.hasCompletedAction = false;
            selectedPlayer   = null;
            selectedWaypoint = null;
            gameState        = GameState.pickPlayer;
        }
    }
コード例 #2
0
    public IEnumerator MovePlayer()
    {
        foreach (Waypoint waypoint in movePath)
        {
            transform.position = new Vector3(waypoint.transform.position.x, transform.position.y, waypoint.transform.position.z);
            gameController.PlayMoveSounds();
            LookForPuck();
            if (hasPuck)
            {
                puck.FollowPlayer();
            }
            yield return(new WaitForSeconds(.25f));

            LookForPuck();
            gameController.actionCompleted = true;
        }
    }