- Home /
4.6 UI Change what 'Spacebar' is doing by default
Hi. So I'm making a game-speed clock for a strategy game (think like Xcom or Empire At War) with 4 buttons on it, and I'm using the new Unity 4.6 UI system with 4 buttons. Each one adjusts the timescale of the game to 0, 1, 10, and 100. See below:
Clicking the buttons works fine, but the EventSystem (I think, but I don't adequately understand it) seems to do what it likes with the spacebar; namely, it will 'click' the last button that I mouse-clicked on. I want to use the spacebar to always alternate between hitting the Pause button and the X1 button, but I can't. To get around this for now I've set the 'left ctrl' ("Dodge" in my input controls, see script below) button to activate these buttons, but I really want to just stop the spacebar doing its own thing so I can use it myself. Any ideas? Here's the script I'm using but I want to get rid of "Dodge" and use "Jump"(default spacebar button).
//FOR SPACEBAR PAUSING OR X1 SPEED
if(Input.GetButtonDown("Dodge"))
{
paused = !paused;
if(paused)
AdjustTimeScale(0);
else if(!paused)
AdjustTimeScale(1);
}
Note that hitting "Dodge" button calls a function 'void AdjustTimeScale(float timeScale)'. Clicking the UI buttons calls the same function with their respective timeScale floats. Hitting "Dodge" does NOT activate a button click directly, though I've no objection to doing that if the solution requires it. I'm just not sure how to make the key translate to a button click so I made the key go straight to the function.
Thanks Kevin
PS I removed all the "jump" (spacebar) inputs from the Input controls but this had no effect.
Answer by Kiwasi · Nov 28, 2014 at 07:11 PM
Go to Edit -> Project Settings -> Input.
In the inspector drop down to submit.
Remove space from the alt positive button.
Answer by RudyTheDev · Nov 29, 2014 at 03:28 PM
See BoredMormon's answer. It's this option (see image) that uses whatever project input settings define for "submit" key. In this case, (alt) key is space bar.
Answer by RudyTheDev · Nov 28, 2014 at 01:27 PM
The event system adds another input to Unity inputs that does the default "click" on the currently focused control. I believe it is the default keyboard input module that defines which key does this. Both components should be under the automatically created EventSystem game object.
The scripts for input are on the event system, yes, but I can't open them. Are you meant to be able to?
No, they are Unity's components, not $$anonymous$$onoBehaviour
scripts. Your project input settings should have an input (besides jump or whatever) used by whatever input module is eating the space bar.
Here's the Inspector for my Event System (I've done nothing to it).
Sorry for my poor circling there but I was pointing to the two "Scripts". I can't open them though. If I double click, $$anonymous$$onoDevelop opens, but only on my last open script. It won't open the new one(s).
I see the 'Submit' field there also but submit is set up as 'enter' and another one as 'return' in the Input manager, but nothing has spacebar on it.
Still at a loss..
Ah, thanks very much $$anonymous$$ormon and $$anonymous$$!
Your answer
Follow this Question
Related Questions
Unity UI Button states 1 Answer
Can't change UI Button Listeners 1 Answer
How to set UI button as selected on mouse over 1 Answer
[4.6 b20] How to make a hold button for the new UI 4 Answers
UI button always selected? 0 Answers