Match 3 Movement Using Keyboard Controls,Match 3 movement using keyboard controls
Hi, I currently have a match 3 game that works using the mouse. You click and drag the pieces to make a match and they disappear and the board refills accordingly like any match 3 game out there. What I want to do is have the arrow keys control what you can do with the mouse. For instance, the arrow keys will navigate the board and highlight the piece that the player is currently on, the player hits enter, selects the piece and presses the key to move it in the desired direction. How would I go about doing this? Any information will help, thank you!,
I'd define a 2D position the cursor is supposed to be (like the array of the grid). on that position, show your marker. with each press, move the position one in the direction (adding or subtracting row or column index). for the action just automate what the mouse drag would be. or just switch the gems and animate the switch. I personally would use an action key with which the keyboard changes from moving to gem switching. Pressing enter every time you went the function to toggle sounds slow.
Answer by UnityCoach · Mar 28, 2017 at 11:23 PM
Unity offers a navigation system that works pretty well. A UI Button
, or any component that inherits from Selectable
will receive navigation events Move, Cancel, Submit.
Here's a quick test you can do :
Create a few UI Buttons
Assign one of them to the EventSystem "FirstSelected" field
Navigate with the keyboard.
By default, the EventSystem uses the Horizontal, Vertical, Submit and Cancel inputs from the Input Settings. And by default, the Input Settings have inputs for the keyboard and Joysticks.
Enter/Space = Submit
Esc = Cancel
You can also implement the ISelectHandler, IMoveHandler, ISubmitHandler and ICancelHandler instead of inheriting from Selectable.
If you find yourself in a situation where navigation becomes tricky, you can have a look at this extension on the AssetStore. I made it to make navigation easier through scroll views and complex ui schemes on consoles and other pointer less platforms.
Your answer
Follow this Question
Related Questions
Join the oldest match (world wide) 0 Answers
How to detect input in InputField in unity when used in android? 0 Answers
logic behind mathc3 games 0 Answers
Test for multiple key presses? 2 Answers
Door Script Problem 1 Answer