Creating Touch Controls in Unity
Creating Touch Controls in Unity
Touch control allows you to interact with your device’s hardware and software. The touch controller receives your touch commands and relays them to the system, so the device can act accordingly. For example, if you touch an icon, the touch controller tells the device to open or execute that app.
There are a number of different types of touch controls, each with its own options to customize how it works. To create a new touch control, select the Touch Controller object in the hierarchy panel and then choose the type of touch control you want to add from the Add Controls area in the inspector.
The most common type of touch control is the button, which can be used to click or tap an object in your application. To create a button, simply select the Touch Controller object in the hierarchy panel then choose the Create Button icon from the Add Controls area in the inspector. The options for a button vary depending on what the button does, but they can include settings to control the appearance and behavior of the button.
A joystick is a kind of stick that can be moved around in a range of directions to perform actions. To create a joystick, select the Touch Controller object in the hierarchy panels then choose Create Joystick from the Add Controls area of the inspector. The joystick has a variety of options to control how it behaves, including whether it is a digital or analog stick, how it snaps to the initial position when touched and what direction its arrows point in.
If you have a joystick, it’s important to note that it should not be ordered after any other control objects (such as a Touch Region or a Custom Controller) that lock the anchored position of the control. This can cause the joystick to not move correctly and will also block raycasting from other control objects that are trying to capture input events on it.
Another thing to note is that you should not attach any Unity UI Layout components to the parent of a Touch Controller or Touch Joystick that have options such as Follow Touch Position or Animate on Return. This can cause the control’s Image to not update when its transition properties change, which can cause unintended or undesirable behavior.