Question by
benrestien · Mar 19, 2020 at 12:07 PM ·
movementinputvariable
Crouching and sprinting doenst work in this script
//CROUCH
if (Input.GetButtonDown("Crouch") && isGrounded && !sprint && speed == 6f)
{
mainCamera.transform.position = new Vector3(transform.position.x, transform.position.y - offset, transform.position.z);
speed = crouchspeed;
crouch = true;
}
if (Input.GetButtonUp("Crouch") || !isGrounded || sprint)
{
mainCamera.transform.position = new Vector3(transform.position.x, transform.position.y + offset, transform.position.z);
speed = 6f;
crouch = false;
}
//SPRINT
if (Input.GetButtonDown("Sprint") && isGrounded && !crouch && speed == 6f)
{
speed = sprintspeed;
sprint = true;
}
if (Input.GetButtonUp("Sprint") || !isGrounded || crouch)
{
speed = 6f;
sprint = false;
}
(Its in Update Method) In this script there are no errors but if I go in play mode the speed doesnt change. It works fine if I delete the speed change in one of the if-statements but if the speed change is in both it doesnt work. The camera y Movement works fine.
Comment
Your answer
Follow this Question
Related Questions
Making an object move non stop after button input? 1 Answer
Change direction of rigidbody when force is no longer being applied 2 Answers
Error on running animating movement code,Question on animation movement 0 Answers
How to tilt a sprite based on pointer position? 1 Answer
What can i change here to have mobile UI button input? 0 Answers