Hi, i have found this piece of code, for what is it question marks and colons?
float horizontalStrafe = Input.GetAxis(“Horizontal Strafe”) < 0 ? -1f : Input.GetAxis(“Horizontal Strafe”) > 0 ? 1f : 0f;
Hi, i have found this piece of code, for what is it question marks and colons?
float horizontalStrafe = Input.GetAxis(“Horizontal Strafe”) < 0 ? -1f : Input.GetAxis(“Horizontal Strafe”) > 0 ? 1f : 0f;
Hey… it’s another sytax for ‘shorthand’ IF statements, to set a variable.
In pseudo code:
if (this < 0) {
variable = “one”
} else {
variable = “two”
}
could be written as:
variable = (this < 0) ? “one” : “two”
The ? denotes then end of the question/if statement
The : denotes the split between both options.