How does Input.anyKey work?
How does Input.anyKey work? does it check a single value, or go through and check every key?
Given I have the following script:
if(Input.anyKey) {
if (Input.GetKeyDown (KeyCode.LeftArrow)) {
} else if (Input.GetKeyDown (KeyCode.RightArrow)) {
} else if (Input.GetKeyDown (KeyCode.UpArrow)) {
} else if (Input.GetKeyDown (KeyCode.DownArrow)) {
}
}
If it checks a single value then it will be more efficient to group my button checks under its single if statement, however, if it checks every button (not just the few I need to check) then it will be more efficient without it.
I think the way you use it there is an unnecessary step. It does nothing in your case.
Well, he wants to avoid the checking of each Input.Get$$anonymous$$eyDown if there's no key pressed at the moment. However since we don't know how exactly any$$anonymous$$ey is implemented we can't tell if this is actually an improvement or not. Of course considering just those 4 keys it's absolutely pointless to do this extra step. It might get interesting if you have 20, 30 or more such if statements.
However in such a case i would rather go with events anyway (using OnGUI or Event.PopEvent). Though be careful with Event.PopEvent. This method will actually remove the event from the queue. The new UI system relies on this method. So when calling it unconditionally every frame you basically prevent the UI system from working normally. OnGUI would be the better solution.
i imagine any$$anonymous$$ey to be a flag raised by the occurence of an event. It'd be totally silly if it iterated all possiblities.
You mentioned a while back that there is some loop/branch in which the contents of the Braces are evaluated anyway whether the condition was correct or not. Was this an if statement or a for loop?