UIJoystick
On-screen joystick that outputs a 2D axis value based on touch position.
Create in the Editor
- Ensure there is a
UIControllerin the scene. - Create a GameObject and add
UIRect. - Add the
UIJoystickcomponent.
How to Use
- Get the component with
myObject.findComponent(UIJoystick.class). - Read and write the component properties to control behavior.
- Test input or layout in Play mode.
Java Example
SpatialObject myObject = /* your object */;
UIJoystick comp = myObject.findComponent(UIJoystick.class);
if (comp != null) {
Texture tex = /* load texture */ null;
// set the backgroundColor value:
comp.backgroundColor = new Color(255, 255, 255, 255);
// read the backgroundColor value:
Color backgroundColorValue = comp.backgroundColor;
// set the backgroundTexture value:
comp.backgroundTexture = tex;
// read the backgroundTexture value:
Texture backgroundTextureValue = comp.backgroundTexture;
// set the handleSizePercentage value:
comp.handleSizePercentage = 1f;
// read the handleSizePercentage value:
float handleSizePercentageValue = comp.handleSizePercentage;
// set the handlerColor value:
comp.handlerColor = new Color(255, 255, 255, 255);
// read the handlerColor value:
Color handlerColorValue = comp.handlerColor;
// set the handlerTexture value:
comp.handlerTexture = tex;
// read the handlerTexture value:
Texture handlerTextureValue = comp.handlerTexture;
}
Notes
- You can replace images or textures in the inspector or via code when the component supports it.