- Home /
if statement error
Hi,
I'm a game dev who is nativly an artist, but wants to learn how to freelance. Therefore I'm reletivly new to scripting. I have an if statement that is errored:
if (Input.GetAxis("W/S") = 0)
{
}
It has three errors:
1: "Assets/Scripts/PlayerController.js(30,34): BCE0044: expecting ), found '='."
2: "Assets/Scripts/PlayerController.js(30,36): BCE0043: Unexpected token: 0."
3: "Assets/Scripts/PlayerController.js(32,16): BCE0044: expecting :, found '='."
Answer by whydoidoit · Jun 14, 2012 at 04:51 PM
A test for equality is "==" - a single "=" is an assignment statement - which is what your problem is, you want to test if something is equal to 0.
No problem - could you mark the question as answered by clicking on the tick? It gets it off the list of unanswered questions.
I was surprised when I saw this question. I've run into something like this before, but it was harder to detect because the language had auto-conversion from numbers to booleans (A$$anonymous$$A > 0 = true). Lucky that Unity doesn't.
Your answer
Follow this Question
Related Questions
WebGL and I/O 1 Answer
Having problems with inputs. 1 Answer
Input Issue 1 Answer
touch input error - finger position offset 2 Answers
Whats wrong with this code? "expecting :, found '=' " error. 2 Answers