- Home /
Unity 5 mobile single stick control
Hi there, I recently update to Unity 5 and now working on a project on mobile platform. I tried to play around with the new CrossPlatformInput in Unity 5 and implement the "MobileSingleStickControl" prefab that built in under 2D asset. But I unable to get the control to work, the controller UI did shown in the screen but user cannot interact with the controller.
I can't find any related example on using the control, mostly what I found are joystick control in Unity 4. Please provide me some example or suggestion on the controller.
Thanks
All works now BUT i cant move and the same time jump! Help please!
Answer by Thiago Baptista · Apr 07, 2015 at 12:10 PM
You've got to have an EventSystem game object in your scene in order to make the virtual joystick work. Just create one in the hierarchy and you`re set.
sorry if this is the wrong spot to post this question. I have got the Joystick to work by adding the Event System. Now my Problem is that every time I touch the sprite it moves all the way to screen location (0,0)? it works but is stuck in the corner.
Answer by ShawnFeatherly · Apr 15, 2015 at 08:08 PM
The most common issue is the joystick popping into a corner, this is fixed by changing Joystick.cs's OnEnable() to Start(). A demonstration of this fix is covered at 5:30 in this video. https://youtu.be/l7YiASYgDC0?t=5m30s
For other issues, watch this video from the start.
Thanks for all the help, awesome I really appreciate the response.
Answer by Textfield272 · Apr 01, 2015 at 08:49 AM
I haven't played around with any of the input prefabs and scripts in the standard assets, but I implemented a single-stick control pretty easily with a basic script.
The property Input.touches
is a Touch[]
that holds all touch input that frame. The state of each Touch
can tell you whether it just began or was there the previous frame, and each touch also has a finger id associated with it that allows you to track the movement of individual fingers. And of course you can get the position on the screen.
A bit of basic logic will allow you to determine if there is a new touch inside the bounds of the control stick, and by subtracting the center of the control stick from the position of the touch, you can get an Vector2
representing the offset. Of course that offset will be in pixels, so you'll probably want to divide that by the radius of the stick in pixels; otherwise the magnitude the control stick gives will vary depending on the DPI of the device.
Hope that helps.
Answer by ulissescad · Jan 07, 2016 at 07:00 PM
Looking at the examples of vehicles made this script and fucionou well for what was proposed . First import the library of standard assets and then simply recall the position as was done in script below. MOVX is a variable for managing the movement by the inspector .
using UnityEngine ; using UnityStandardAssets.CrossPlatformInput ; using System.Collections;
public class Mov : { MonoBehaviour
public float MOVX ;
// Use this for initialization void Start ( ) {
// Joystick.
}
// Update is called once per frame void Update () {
Debug.log ( Input.GetAxisRaw ( " Horizontal "));
this.transform.Translate ( CrossPlatformInputManager.GetAxis ( " Horizontal " ) * * MOVX Time.deltaTime , 0 , 0);
} }
Answer by danifou · Nov 10, 2016 at 11:48 AM
i have a simlar problem but its a bit diferent i can t cheak the box at the left corner at the top i got that asset from standar assets
Your answer
Follow this Question
Related Questions
How access asset files in android/ios 0 Answers
Mobile joystick not moving player 0 Answers
Mobile Virtual Joysticks / Keyboard Script Conversion 0 Answers
Mobile Game Different Screen Size Issue 2 Answers