コード例 #1
0
    void Update()
    {
        ownTBear.SetActive(canThrow ? true : false);

        float x = Input.GetAxis("Horizontal");
        float y = Input.GetAxis("Vertical");

        if (!canMove)
        {
            x = 0; y = 0;
        }

        Vector2 dir = new Vector2(x, y);

        Walk(dir);

        anim.SetHorizontalMovement(x, y, rb.velocity.y);

        if (coll.triggerPush)
        {
            WallJump(true);
        }

        if (coll.onGround)
        {
            wallJumped = false;
            GetComponent <BetterJumping>().enabled = true;
        }

        rb.gravityScale = 3;

        if (coll.onWall && !coll.onGround)
        {
            if (x != 0)
            {
                wallSlide = true;
                WallSlide();
            }
        }

        if (!coll.onWall || coll.onGround)
        {
            wallSlide = false;
        }

        isWalking = (!coll.onWall && coll.onGround && x != 0) ? true : false;

        if (!stepSource.isPlaying && isWalking)
        {
            stepSource.Play(); // Step sounds
        }

        if (!isWalking)
        {
            stepSource.Stop();
        }

        if (wallSlide)
        {
            GetComponent <SoundEffects>().playSlideAudio();
        }
        else
        {
            GetComponent <SoundEffects>().stopSlideAudio();
        }

        if (Input.GetButtonDown("Jump") && canMove)
        {
            anim.SetTrigger("jump");

            if (coll.onGround)
            {
                Jump(Vector2.up, false);
            }
            if (coll.onWall && !coll.onGround)
            {
                WallJump(false);
            }
        }

        if (Input.GetButtonDown("Fire1") && canThrow && (playerLevel > 0))
        {
            anim.PrepareThrow();
        }

        if (Input.GetButtonDown("Fire2") && !canThrow && (playerLevel > 0))
        {
            TBearRetrieve();
        }

        if (coll.onGround && !groundTouch)
        {
            GroundTouch();
            groundTouch = true;
        }

        if (!coll.onGround && groundTouch)
        {
            groundTouch = false;
        }

        WallParticle(y);

        if (wallSlide || !canMove)
        {
            return;
        }

        FlipAnim(x);
    }