I'm not sure you can use key combinations as input, so you may need to set up two buttons and then check for a GetButton on the shift during a GetButtonDown on the W.
Input manager configuration:
Sprint
Positive Button: w
Shift
Positive Button: left shift
Alt Positive Button: right shift
That will allow either shift to be used. If you don't want that, leave the Alt Positive Button blank. Negative buttons and other alt buttons can be left blank. All the other settings should be fine.
Then your code would look something like this:
if (isGrounded && Input.GetButton("Shift") && Input.GetButtonDown("Sprint")) {
isRunning = true;
}
if (Input.GetButtonUp("Shift") || Input.GetButtonUp("Sprint")) {
isRunning = false;
}
Or, as @DMGregory pointed out, the code can be simplified to one line:
isRunning = isGrounded && Input.GetButton("Shift");
This has slightly different behavior, since it triggers when holding w
first and then beginning to hold shift
, whereas the first code example only triggers when you hold shift
first. I don't know exactly what controls you want, but the second code example is probably better.
##Edit
It turns out I was overthinking this. You already have W
assigned to your Vertical axis, which you are using. Just have isRunning equal the state of the shift key.
//Sprint
// Positive Button: left shift
// Alt Positive Button: right shift
isRunning = GetButton("Sprint");