Cubes are like characters. You can use the joystick in the lower right corner to control character movement
Look at the structure chart
Image1: It's the outer circle.
Image2: It's a blue circle.
Create JoyStickScript.cs code to mount on Image2. Control cube movement is not implemented here. needs to be improved
1 usingUnityengine;2 usingSystem.Collections;3 usingUnityengine.ui;4 usingUnityengine.eventsystems;5 6 /// <summary>7 ///rocker Lever8 /// </summary>9 Public classJoystickscript:monobehaviour, Ibegindraghandler, Idraghandler, IenddraghandlerTen { One AGameobject Player;//Moving Objects - -Vector3 originposition;//Start coordinates the Vector3 newposition; - Public floatRadius = +;//Maximum radius of scrolling - floatHorizontal; - floatVertical; + floatSpeed ; - voidAwake () + { APlayer = Gameobject.findwithtag ("Player"); at } - - //Use this for initialization - voidStart () - { - //originposition = transform.position;//Record Origin location in } - to //Update is called once per frame + voidUpdate () - { the //Float horizontal = Input.getaxis ("horizontal"); * //float veritcal = (TRANSFORM.POSITION.Y-ORIGINPOSITION.Y)/Radius; $ //vertical = (TRANSFORM.POSITION.Y-ORIGINPOSITION.Y)/Radius;Panax Notoginseng //horizontal = (transform.position.x-originposition.x)/Radius; - //Player.transform.Translate (horizontal, vertical, 0); the //Debug.Log (vertical); + A } the + Public voidOnenddrag (pointereventdata eventData) - { $Transform.position = originposition;//homing to Origin $ } - - Vector3 dir; the Public voidOndrag (pointereventdata eventData) - {Wuyi theDir = (Input.mouseposition-originposition). normalized; - WuTransform.position = input.mouseposition;//set Current joystick position - About //when it's over the outside Circle $ if(Vector3.distance (Input.mouseposition, originposition) >Radius) -transform.position = originposition + dir *Radius; - - //vertical = (TRANSFORM.POSITION.Y-ORIGINPOSITION.Y)/Radius; A //horizontal = (transform.position.x-originposition.x)/Radius; +Print (Originposition + dir *Radius); thePlayer.transform.position = dir *Time.deltatime; - } $ the Public voidOnbegindrag (pointereventdata eventData) the { theOriginposition = transform.position;//Record Origin location the } -}
Ugui Implement Joystick