Good afternoon, I have a problem with an input in my code: Before testing it on mobile I tried on PC and the code to make my player sprint was like this:
var sprintPressed = Input.GetKey(KeyCode.LeftShift);
var targetSpeed = maxSpeed;
if (attacking) {
targetSpeed *= attackMoveSpeedMultiplier;
}
else if (sprintPressed) {
targetSpeed *= sprintMultiplier;
}
And everything was working fine. My player increases the movement speed as soon as I press "Left Shift" button. Then I changed the code to make it work with a mobile button:
var sprintPressed = CrossPlatformInputManager.GetButton("Sprint");
var targetSpeed = maxSpeed;
if (attacking) {
targetSpeed *= attackMoveSpeedMultiplier;
}
else if (sprintPressed) {
Debug.Log(sprintPressed ? sprintMultiplier : 1);//just to see if it take a button
targetSpeed *= sprintMultiplier;
}
I also make a change for a controller so instead, to press WASD I use a screen joystick. That's work fine. But when I press a button to make a sprint, nothing happens. I insert a debug log line and when I press a button it just return 1 single value (sprintMultiplier) and not 1 per frame as it should be because this function is in the Fixed Update. I check in Google and I found this tutorial https://www.youtube.com/watch?v=nGYObojmkO4&t=851s&list=PLXVRS21ln3JIbFLPwf9bdH3thHmmYRJGi&index=16 Pretty much what I did but in his video, it's working. In my project doesn't. Can someone help me, please? Many thanks beforehand