- Home /
3d car left and right touch input
Hey, i'm developping a 3d car game and untill now, i used computer input to move it. But i want to make the left and right touch. I've made two invisible buttons that take the left and right half of tje screen. And i want them to control the steering of the car. I have an input manager where i defined a public float steer variable and i made it equal to :
steer = Input.GetAxis('Horizontal')
How do i make the touch buttons control the steering ?
Answer by Zoedingl · Jul 21, 2020 at 03:23 PM
Hello. Instead of using Input.GetAxis(), You can create a input manager, which will check if the butons are clicked, or not.
Answer by HexStudio · Aug 01, 2020 at 09:27 PM
Yes, that's what i want to do, but i don't know how to.
Hello,The idea is, that you write a script, which will update it`s fields when any of the buttons is pressed. These fields will be used as Input.GetAxis(). there are just some if statements needed. if both buttons are pressed or both aren`t pressed then the axis is 0.
if only one is pressed, tha value is changing according to which button is pressed.
Note: these events can be accessed through the Button element under the GameObject. You just need a reference to it and you should do something like this: leftButton.onClick.addListener(); //And pass the listener in the method. Do this for each of the buttons. I hope, that this helped. :D
Your answer
Follow this Question
Related Questions
Give Car Direction Using Single Touch 1 Answer
Raycasting UI elements - Without using Event Triggers 0 Answers
How do I change this 2D script to touch controls to go up and down with swipe or on screen buttons? 1 Answer
Make an obect take priority over another when touched? 0 Answers
how to only get the negative or positive part of a GetAxis 1 Answer