예제 #1
0
    void FixedUpdate()
    {
        //Ground check for double jump
        //if (isGrounded()) {
        //	onFirstJump = false;
        //}

        //TODO: Testing
        if ((Input.GetKeyDown(KeyCode.Q)))
        {
            FreezePlayer(false);
        }
        if ((Input.GetKeyDown(KeyCode.O)))
        {
            canDoubleJump = true;
        }

        //Freeze check
        if (playerFrozen)
        {
            anim.SetFloat("Speed", 0);
            anim.SetBool("SetJumping", false);
            anim.SetBool("SetDigging", false);
            anim.SetBool("SetAttacking", false);
            isRunning   = false;
            isAttacking = false;
            isDigging   = false;
            //TODO: Any checks that require a frozen player
            return;
        }

        //Interact
        if ((Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)) && atNPC)
        {
            NPC.BeginInteraction();
            //TODO: Get NPC collider, do thing, unfreeze once complete
        }

        //Movement
        if ((Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) && !isDigging)
        {
            //Go left
            anim.SetFloat("Speed", speed);
            isRunning = true;
            changeDirection("left");
            transform.Translate(Vector3.left * speed * Time.deltaTime);
        }
        else if ((Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) && !isDigging)
        {
            //Go right
            anim.SetFloat("Speed", speed);
            isRunning = true;
            changeDirection("right");
            transform.Translate(Vector3.right * speed * Time.deltaTime);
        }
        else if (isGrounded())
        {
            anim.SetFloat("Speed", 0);
            isRunning = false;
        }

        //Jump
        if (Input.GetKeyDown(KeyCode.Space) && !isDigging && !isAttacking)
        {
            if (/*isGrounded() ||*/ numJumps < 1)               //Either on the ground, or fell off a platform and hasn't jumped yet
            {
                anim.SetBool("SetJumping", true);
                rb.velocity = new Vector2(rb.velocity.x, 0);
                rb.AddForce(new Vector2(0, 260));
                numJumps = 1;
            }
            else if (canDoubleJump && numJumps <= 1)             //In the air and has only jumped once, if they are able to double jump
            {
                anim.SetBool("SetDoubleJump", true);
                numJumps    = 2;              //Disables jumping after this
                rb.velocity = new Vector2(rb.velocity.x, 0);
                rb.AddForce(new Vector2(0, 260));
            }
        }

        //Dig
        if (Input.GetKey(KeyCode.P) && !isAttacking && isGrounded())
        {
            isDigging = true;
            anim.SetBool("SetDigging", true);
            //TODO: Dig stuff, freeze player motion
        }

        //Attack
        if ((Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) && !isDigging)
        {
            isAttacking = true;
            anim.SetBool("SetAttacking", true);
        }
    }