- Home /
How to make only one directional button available at one time.
So I'm a complete noob when it comes to unity and I want to attempt something that I don't know how to attempt. I basically want to make it so that when the player hits a direction button the player game object will move in that direction until it hits a collider and stops. I also want to make it so that the player can only travel up, down, left, and right and have it so that the player can only move in one direction at a time. Do any of you know what I can do to achieve this? This is for a 2d game by the way.
Answer by djenningsais · Oct 18, 2017 at 01:04 AM
@Sbarros -
Welcome!!
You need to create a control script. In your script you should utilize the Update method to check for keystrokes. If you want controls to be disabled you may need a class variable to keep track of the status of whether keystrokes are being accepted. Make sure you are checking https://docs.unity3d.com/Manual/index.html on your journey. Also the Unity Tutorials are outstanding: https://unity3d.com/learn/tutorials
Hopefully these suggestions get you started. If you need more hints along the way don't hesitate to ask.
Your answer
![](https://koobas.hobune.stream/wayback/20220612141307im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
OnCollisionEnter2D not triggering on parent 1 Answer
How to prevent sliding when walking up slopes in 2D? 1 Answer
2D Snail-like movement 1 Answer
How to Make Characters Stick to Walls? 2D (c#) 2 Answers
2d space gravity? 2 Answers