void Update()
    {
        //horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

        if (Input.GetButton(leftbutton))
        {
            if (Input.GetButton(rightbutton))
            {
                horizontalMove = 0;
            }
            else if (!Input.GetButton(rightbutton))
            {
                horizontalMove = -1;
            }
        }
        else
        {
            if (Input.GetButton(rightbutton))
            {
                horizontalMove = 1;
            }
            else if (!Input.GetButton(rightbutton))
            {
                horizontalMove = 0;
            }
        }
        horizontalMove *= runSpeed;

        animator.SetFloat("Speed", Mathf.Abs(horizontalMove));

        if (Input.GetButtonDown(jumpbutton))
        {
            SoundManager.soundmanager.SFXPlay(jumpSound);
            jump = true;
        }
        if (Input.GetButton(crouchbutton))
        {
            crouch = true;
        }
        else if (Input.GetButtonUp(crouchbutton))
        {
            crouch = false;
        }
        if (Input.GetButtonDown(shootbutton))
        {
            SoundManager.soundmanager.SFXPlay(shotSound);
            weapon.Shoot();
        }
    }
예제 #2
0
    void Update()
    {
        float   x    = Input.GetAxis("Horizontal");
        float   y    = Input.GetAxis("Vertical");
        float   xRaw = Input.GetAxisRaw("Horizontal");
        float   yRaw = Input.GetAxisRaw("Vertical");
        Vector2 dir  = new Vector2(x, y);

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


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

            if (coll.onGround)
            {
                Jump(Vector2.up, false);
            }
        }

        if (Input.GetButtonDown("Fire1"))
        {
            anim.SetTrigger("shoot");
            weapon.Shoot();
        }

        if (x > 0 && side == -1)
        {
            // ... flip the player.
            side = 1;
            anim.Flip(side);
        }
        // Otherwise if the input is moving the player left and the player is facing right...
        else if (x < 0 && side == 1)
        {
            // ... flip the player.
            side = -1;
            anim.Flip(side);
        }
    }