2
\$\begingroup\$

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?

example touch interface with buttons

\$\endgroup\$
1
\$\begingroup\$

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:

  1. In the scene create new and select UI->Button
  2. Select the new button in the scene and find its Button script in the inspector
  3. Make a new on click event
  4. 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

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.