Exemplo n.º 1
0
    private void FixedUpdate()
    {
        if (stateManager.currentState == "fetch")
        {
            if (stateVariables.stickThrown)
            {
                rb.AddTorque(-rb.velocity.x / 2);
                if (transform.position.y <= stateVariables.GetThrowTarget().position.y)
                {
                    Debug.Log("hit ground");
                    hitGround = true;

                    rb.velocity        = new Vector3();
                    rb.gravityScale    = 0;
                    rb.angularVelocity = 0;
                    rb.freezeRotation  = true;
                }
            }

            if (transform.position == stateVariables.GetFetchStartingPoint().position)
            {
                Debug.Log("hit ground");
                hitGround = true;

                rb.velocity        = Vector3.zero;
                rb.gravityScale    = 0;
                rb.angularVelocity = 0;
                rb.freezeRotation  = true;
            }
        }
    }
    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));
            }
        }
    }