- Home /
Question by
spol1311 · Mar 30, 2020 at 06:38 PM ·
c#if-statementsifvaluesxbox controller
Use multiple values for "if" statement
I want to make my character go faster when the Trigger Button of my Xbox Controller is 'half pressed'. The 'return value range' goes from -1 to 1. In my script 1 (Trigger is fully pressed) means running, -1 (Trigger isn't pressed) means 'default speed'. I want my character to go a bit faster when the Trigger is half pressed, meaning values between -0.3 and 0.3. How can I assign my if statement all numbers between -0.3 and 0.3?
Comment
Answer by nickk2002 · Mar 30, 2020 at 06:47 PM
I guess you could use something like this
float value = Input.GetAxis("Vertical");// or the axis name
float speed = 0;
if (-0.3f <= value && value <= 0.3f)
{
speed = value * 2f;
}
else
speed = value;
transform.position += new Vector3(0, 0, speed);
Your answer
Follow this Question
Related Questions
Input.GetKey(KeyCode.E) requires multiple presses. 1 Answer
play an audio clip in an if statement 2 Answers
If statements not working right 1 Answer
Conflicting Animator SetTrigger 1 Answer
Multiple Cars not working 1 Answer