Have noticed this line in one of the bundled Unity scripts. Am not familiar with the use of comparison operators when setting a variable. Can anyone explain what it means?
movement.isMoving = Mathf.Abs (inputDirection) > 0.1;
Have noticed this line in one of the bundled Unity scripts. Am not familiar with the use of comparison operators when setting a variable. Can anyone explain what it means?
movement.isMoving = Mathf.Abs (inputDirection) > 0.1;
movement.isMoving is a boolean variable, You are checking whether the value of input direction is more than 0.1 either in negative or positive…
basically Mathf.Abs(inputDirection)>0.1 is a condition so it will return either true or false to the variable isMoving.
This is equal to
if(Mathf.Abs (inputDirection) > 0.1)
{
movement.isMoving=true;
}
else
{
movement.isMoving=false;
}
Aditional: Check ternary operator is more like a simple if else loop that could also be used during variable declaration, with a condition.
eg: var x=(y<3?3:3);
this will clamp the value to 3 if the value is 3 or more or you will get the value of y in x. Hope it is clear