r/UnityHelp • • Jan 30 '22

PROGRAMMING Movement Script Troubles

I have a simple crouch and sprint script written here along with my movement script, but if I press shift/ctrl it will do what it’s supposed to but then it will stay stuck that way. Like when I press left shift it speeds up but if I let go it stays sped up. Same applies to the left ctrl. Please help.

Thanks in advance!

2 Upvotes

3 comments sorted by

3

u/ryemck93 Feb 01 '22

Need to have the keydown and keyup in there

if (Input.GetKeyDown(KeyCode.LeftShift))
playerSpeed = 6.0f;
else if (Input.GetKeyUp(KeyCode.LeftShift))
playerSpeed = 3.0f;
}

2

u/Fancy_Edge2509 Jan 30 '22

You need to get the script to check if shift and control have been released so it can return the character to the original position.

1

u/cone5000 Jan 30 '22

Gotta share the script