Unity/Javascript Operators

I am trying to use an 'or' operator in an if statement, and Unity is telling me it's an unexpected token.

What does Unity recognize as an 'or' operator? Found little in the script ref.

Thank you for the help!

You use two vertical "pipes" for or.



It's nice, because it "short circuits". That is, if the first statement is true, it won't bother to evaluate any more statements. So if you have a statement that is likely to be true most of the time, more so than another statement, put that first for more efficient code.

What you currently have is:

if (Input.GetAxis("P1_HorizontalAim")) || (Input.GetAxis("P1_VerticalAim")) {
    isTurning = true;

First, the entire conditional part of the if state needs to be in parentheses. Second, I suspect that Javascript wants a boolean value in the if - and Input is returning a float. Try this instead:

if ((Mathf.Abs(Input.GetAxis("P1_HorizontalAim")) > 0.1) || 
    (Mathf.Abs(Input.GetAxis("P1_VerticalAim")) > 0.1)) {
    isTurning = true;

Update: confirmed that, yet again, Eric5h5 is right - this code does work, I tested it:

function Update () {
    if (Input.GetAxis("Horizontal") || 
        Input.GetAxis("Vertical")) {
        isTurning = true;

The only question I would have, is if physical joysticks can generate spurious values, or whether Unity filters them out below a certain threshold.