public void MoveTowards() { if (!stateVariables.movingTowardsPlayer) { StopAllCoroutines(); PathRequestManager.ClearRequests(); Debug.Log("Call Request"); stateVariables.movingTowardsPlayer = true; currentlyOnPath = false; stateVariables.desintationReached = false; } if (!currentlyOnPath && !stateVariables.desintationReached) { Debug.Log("moving to new towards player"); if (transform.position.x > player.transform.position.x) { Debug.Log("Moving to the right target"); // Right walk target PathRequestManager.RequestPath(transform.position, player.transform.GetChild(4).transform.position, OnPathFound); } else { Debug.Log("Moving to the left target"); // Left walk target PathRequestManager.RequestPath(transform.position, player.transform.GetChild(5).transform.position, OnPathFound); } currentlyOnPath = true; } }
IEnumerator FollowPath() { Vector3 currentWaypoint = path[0]; while (true) { if (transform.position == currentWaypoint) { //Debug.Log("At waypoint: " + path[targetIndex]); targetIndex++; if (targetIndex >= path.Length) { PathRequestManager.ClearRequests(); currentlyOnPath = false; Debug.Log("Reached Destination"); if (stateManager.currentState == "move towards") { stateVariables.callRequestMade = false; stateVariables.movingTowardsPlayer = false; } stateVariables.desintationReached = true; yield break; } currentWaypoint = path[targetIndex]; } transform.position = Vector3.MoveTowards(transform.position, currentWaypoint, stateVariables.walkSpeed * Time.deltaTime); if (currentWaypoint.x < transform.position.x) { sprite.flipX = true; } else { sprite.flipX = false; } yield return(null); } }
IEnumerator FollowPath() { Vector3 currentWaypoint = path[0]; while (true) { if (transform.position == currentWaypoint) { Debug.Log("At waypoint: " + path[targetIndex]); targetIndex++; if (targetIndex >= path.Length) { PathRequestManager.ClearRequests(); yield break; } currentWaypoint = path[targetIndex]; } transform.position = Vector3.MoveTowards(transform.position, currentWaypoint, 5 * Time.deltaTime); } }
public void Wait() { currentlyOnPath = false; PathRequestManager.ClearRequests(); stateVariables.callRequestMade = false; stateVariables.movingTowardsPlayer = false; anim.SetBool("isRunning", false); anim.SetBool("isWalking", false); anim.SetBool("isSitting", false); if (transform.position.x > player.transform.position.x) { sprite.flipX = true; } else { sprite.flipX = false; } }
public void Launch() { // Increasing Current Island Count gm.IncreaseIsland(); //Debug.Log("Transitioning to island: " + gm.GetCurrentIsland()); // Enabling & Disabling Monty, Player, Canoe Single and their depencies //canoeAIO.transform.position = canoeSpawnPoints[gm.GetCurrentIsland()-1].transform.position; canoeAIO.GetComponent <CanoePaddle>().beached = false; canoeAIO.GetComponent <CanoePaddle>().launched = false; player.GetComponent <PlayerController>().canLaunch = false; player.GetComponent <PlayerController>().interactionType = ""; canoeAIO.GetComponent <CanoePaddle>().canPaddle = true; canoeAIO.GetComponent <Rigidbody2D>().simulated = true; layerManager.SetActive(false); interactionsManager.SetActive(false); pathwayColliders[gm.GetCurrentIsland() - 1].SetActive(false); spritesManager.SetActive(true); //Setting all other pathfinding managers to inactive for (int i = 0; i < pathfindingManagers.Length; i++) { pathfindingManagers[i].SetActive(false); } // Activating the next islands pathfinding and clearing any existing path requests pathfindingManagers[gm.GetCurrentIsland()].SetActive(true); PathRequestManager.ClearRequests(); monty.GetComponent <MontyStateActions>().StopAllCoroutines(); montyStateVariables.grid = pathfindingManagers[gm.GetCurrentIsland()].GetComponent <MyGrid>(); //hide monty //hide canoe object //show canoe all in one at the new location cameraHandler.SwitchToCanoe(); }
public void Fetch() { if (!pathCancelled) { PathRequestManager.RequestPath(transform.position, transform.position, OnPathFound); PathRequestManager.ClearRequests(); StopAllCoroutines(); pathCancelled = true; } //checking if the stick hasn't been thrown yet, or monty is bringing the stick back (when to move monty to the start point) if (!stateVariables.stickThrown || stateVariables.montyReturningStick) { transform.position = Vector3.MoveTowards(transform.position, stateVariables.GetFetchStartingPoint().position, stateVariables.runSpeed * Time.deltaTime); anim.SetBool("isWalking", false); anim.SetBool("isSitting", false); anim.SetBool("isRunning", true); stateVariables.montyHasStick = false; stateVariables.waitedAtStick = false; if (stateVariables.montyReturningStick) { sprite.flipX = true; } else { sprite.flipX = false; } } //checking if the stick has been thrown (when to move monty towards the stick after being thrown) else if (stateVariables.stickThrown) { transform.position = Vector3.MoveTowards(transform.position, stateVariables.GetThrowTarget().position, stateVariables.runSpeed * Time.deltaTime); cameraHandler.SwitchToMonty(); anim.SetBool("isWalking", false); anim.SetBool("isSitting", false); anim.SetBool("isRunning", true); sprite.flipX = false; } //checking if monty is at the starting point if (transform.position == stateVariables.GetFetchStartingPoint().position) { cameraHandler.SwitchToPlayer(); //Resetting animator and facing in the correct spot //Debug.Log("Monty at stick"); anim.SetBool("isWalking", false); anim.SetBool("isRunning", false); anim.SetBool("isSitting", true); sprite.flipX = true; stateVariables.stickThrown = false; stateVariables.montyHasStick = true; stateVariables.montyReturningStick = false; if (stateVariables.playerHasStick) { //Debug.Log("Disable input"); playerController.DisablePlayerInput(); stateVariables.montyHasStick = false; stateVariables.GetFetchStick().transform.GetChild(0).GetComponent <SpriteRenderer>().enabled = false; } else { //Debug.Log("enable input"); StartCoroutine(playerController.EnablePlayerInput(0)); stateVariables.montyHasStick = true; stateVariables.GetFetchStick().transform.GetChild(0).GetComponent <SpriteRenderer>().enabled = true; } } //checking if monty is at the stick after being thrown if (transform.position == stateVariables.GetThrowTarget().position) { //Debug.Log("At thrown stick"); anim.SetBool("isRunning", false); if (!stateVariables.waitedAtStick) { StartCoroutine(WaitForTime(2)); } } }