The question is answered, right answer was accepted
My character won't stop crouching, they dont stop crouchin
My character won't stop crouching
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovment : 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 Character
controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
}
Sorry, I forgot mentioning that. To use GetKeyDown, you need a keycode (most probably). For example, if you want to press space to crouch write: Input.GetKeyDown(Keycode.Space) or for A Input.GetKeyDown(Keycode.A)
Answer by KeksKuchen15 · Feb 17, 2021 at 03:45 PM
I found my own mistake I have forgotten to add and select the layer for the player and the ground because of that the ground detection hasn't work right.
Answer by WolfM1nd · Feb 17, 2021 at 08:02 AM
I think you should change GetButtonDown to GetKeyDown. I hope it works.
Sadly it doesn't work. Because the GetKeyDown skipping the axes definitions in the Input manager. Then the following Error comes: ArgumentException: Input Key named: Crouch is unknown UnityEngine.Input.GetKeyUp (System.String name) (at :0) PlayerMovment.Update () (at Assets/PlayerMovment.cs:28) Because of the fact that the GetKeyDown skipping the axes definitions
Sorry, I forgot mentioning that. To use GetKeyDown, you need a keycode (most probably). For example, if you want to press space to crouch write: Input.GetKeyDown(Keycode.Space) or for A Input.GetKeyDown(Keycode.A)
I don't know if you can see the submessages, so I will also share this as another message.
Hey Guys I think your Using The brackeys Tutorial you know he said to download the code In that code in Line 67 There will be line
if (!crouch)
If its like this remove The " ! "
the result should be like
if (crouch)
This should do it my friend
Follow this Question
Related Questions
"Invalid argument"? 0 Answers
Player Not Moving With Platform 2D 1 Answer
Cannot delay player respawn. 2 Answers
How to make the next level load based on 2 characters touching a collider? 0 Answers
2d platformer physics 0 Answers