Bracket error
I am trying to use numbers in my script but i can't do it because Unity show those errors: Why? This is so strange! Why does a simple number bug the script? This doesn't make any sense...
Here is the code that gives the problem (Javascript):
function Update ()
{
if (Input.GetKeyDown ("1"))
}
Answer by Lardalot · Oct 30, 2016 at 12:35 AM
Your If statement isn't doing anything, and the way you're looking up what key is pressed isn't right. You need something like:
function Update ()
{
if (Input.GetKeyDown (KeyCode.Alpha1))
{
//Do stuff in here.....
}
}
Actually, using the string input "1" will work (though you're right to say it's bad practice - https://docs.unity3d.com/$$anonymous$$anual/ConventionalGameInput.html). The reason for the error is the misformed structure of the if statement.
Ahh thanks @tanoshimi, I didn't know you could use the string version of the character.
Your answer
Follow this Question
Related Questions
Hi! I am trying to use SceneManagement, but I keep getting errors. 1 Answer
Getting error on lap counter script JS 0 Answers
How to setactive Car Script on writing script on Java on Android platform 0 Answers
NullReferenceException: Object reference not set to an instance of an object 1 Answer
Walking animation javascript? 2 Answers