/* * // This code is no longer necessary as a more efficient sprite swap * * public void RevertSprite() * { * if (interactionsManager.interaction.forceFaceRight && !facingRight) * { * sprite.flipX = true; * } * else if (interactionsManager.interaction.forceFaceRight && facingRight) * { * sprite.flipX = false; * } * } * */ void HandleMonty() { //checking if monty has the stick and the player is within range of picking it up if (interactionType == "pickUpStick") { montyStateVariables.GetFetchStick().transform.GetChild(0).GetComponent <SpriteRenderer>().enabled = false; DisablePlayerInput(); currentInventoryIndex = 0; anim.SetInteger("inventoryIndex", currentInventoryIndex); anim.SetTrigger("pickUpStick"); //setting the position of the stick object to around the players arm height (can easily be changed by moving the target object in the scene) montyStateVariables.GetFetchStick().transform.position = transform.GetChild(3).transform.position; montyStateVariables.playerHasStick = true; montyStateVariables.montyHasStick = false; } if (interactionType == "throw") { anim.SetTrigger("throwStick"); Debug.Log("Throw Stick"); } }
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)); } } }