(2D) What is wrong with my code that is preventing me from crouching ? - PlayerMovement Script 2D
For some reason, even though I have implemented the crouching mechanic into this code, nothing is happening in the actually game. Can anyone help? I'm new to coding.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController2D controller;
public float runSpeed = 40f;
float horizontalMove = 0f;
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()
{
//Move our character
controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
}
from Recent Questions - Stack Overflow https://ift.tt/3IYTGUd
https://ift.tt/eA8V8J
Comments
Post a Comment