Skip to content

Jump and Crouch Not Working #48

@AnshrajGamez

Description

@AnshrajGamez

My code:

`using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
CharacterController2D controller2D;
float horizontalMove = 0f;
float runSpeed = 70f;
bool jump = false;
bool crouch = false;
// Update is called once per frame
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
if (Input.GetButtonDown("Jump"))
{
jump = true;
}

    if (Input.GetButtonDown("Crouch"))
    {
        crouch = true;
    }
    else if (Input.GetButtonUp("Crouch"))
    {
        crouch = false;
    }
}

void FixedUpdate()
{
    controller2D = GameObject.Find("Player").GetComponent<CharacterController2D>();
    controller2D.move(horizontalMove * Time.fixedDeltaTime, crouch, jump, controller2D.GetOnCrouchEvent());
    
}

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions