I'm trying to make a racing game on android using unity. I want to make a car move forward when I touch an image button like in the picture below. I've already made it work using the keyboard. How do I do the same with on-screen buttons and touch input in android?
1 Answer
If you are using Unity 4.6+ then you have access to its new UI system. If you ever used NGUI, which is a popular unity UI frame work, its based on that architecture I believe.
This is a good tutorial on the subject of buttons and how they work.
http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-button
Quick summary tho:
- In the scene create new and select UI->Button
- Select the new button in the scene and find its Button script in the inspector
- Make a new on click event
- Assign the object you want to act on when the button is press and the function to call (whatever your current movement code is)
At step #2 if you want to listen for more specific events just add a new EventTrigger script and pick a more specific event type and set it up by assigning an object and callback.
More on that here: http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-events-and-event-triggers