Hello,
I got this small FPS game and I am trying to understand this C# Script:
void FixedUpdate()
{
float vScale = 1.0f;
float speed;
if ((Input.GetKey(“left shift”))
{
speed = runSpeed;
}
if (Input.GetKey(“c”))
{ // press C to crouch
vScale = 0.5f;
speed = crchSpeed;
}
Both runSpeed and crchSpeed were declared but in-game when I crouch my player does not slow down, however when I press shift, my player picks up the pace. How come runSpeed works but crchSpeed does not? Cheers!
void FixedUpdate()
{
float vScale = 1.0f;
float speed;
if ((Input.GetKey("left shift"))
{
speed = runSpeed;
}
if (Input.GetKey("c"))
{ // press C to crouch
vScale = 0.5f;
speed = crchSpeed;
}
It’s incomplete… but with what is there is during FixedUpdate we define a temporary variable ‘speed’, if the ‘left shift’ key is pressed we set that variable to ‘runSpeed’, and if the C key is pressed we instead change the ‘speed’ to ‘crchSpeed’ and the vScale to ‘0.5’.
What you then do with vScale and speed is beyond any of us, because that’s all you show.
I’m going to guess it’s used to move some Rigidbody around at some speed depending on user input.