Ugui Realized variable speed joystick

Source: Internet
Author: User

Last year just finished Ugui, want to be a snake games ~
The result, of course, is that, like most program apes, the core operating logic is implemented, and the rest is behind.
But yesterday on the Internet to see the same as I this demo post, I snake snake Head is also copied, this really can not endure, or the original put out good ~

--- point here ---

So simple Chinese + Pinyin programming style I'm afraid I have the nerve to use.

Using system;using unityengine;using unityengine.eventsystems;using unityengine.ui;  public class joyplayerctrl:monobehaviour{public enum axisoption {Both,//Use Both onlyhorizontal,    Only horizontal onlyvertical//Only vertical} public joystickinput Mjoystick;    public int distance max = 100;    Public axisoption axestouse = Axisoption.both; BOOL M_usex; Toggle for using the x axis bool M_usey;    Toggle for using the Y axis Vector3 startpos;      Vector3 Firstpos;    Image IMGBG;     Public Image Imgcheck;    public static Joyplayerctrl Instance;         void Awake () {Instance = this;        IMGBG = getcomponent<image> ();        M_usex = (Axestouse = = Axisoption.both | | axestouse = = axisoption.onlyhorizontal);         M_usey = (Axestouse = = Axisoption.both | | axestouse = = axisoption.onlyvertical);        Mjoystick = new Joystickinput ();        Mjoystick. Distance max = distance max;        startpos = transform.localposition; OnpoInterup (); } void Update () {if (Input.getkeydown (KEYCODE.MOUSE0)) {Onpointerdown (new Vector2 (Input.        Mouseposition.x, INPUT.MOUSEPOSITION.Y)); } if (Input.getkey (KEYCODE.MOUSE0)) {Ondragduan (new Vector2 (input.mouseposition.x, Input.mousepo        SITION.Y));        } if (Input.getkeyup (KEYCODE.MOUSE0)) {Onpointerup (); }}///<summary>///For the first time Press///</summary>/<param name= "Mousepos" ></param> p        ublic void Onpointerdown (Vector2 mousepos) {imgbg.enabled = true;        Imgcheck.enabled = true;        Mjoystick.isuser = true;         IMGCheck.transform.localPosition = Vector3.zero;        Firstpos = Mousepos;    Transform.localposition = new Vector3 (MOUSEPOS.X-SCREEN.WIDTH/2, MOUSEPOS.Y-SCREEN.HEIGHT/2, startpos.z); }///<summary>//Bounce up///</summary> public void Onpointerup () {imgbg.enabled= false;        imgcheck.enabled = false;    Mjoystick.isuser = false; }///<summary>//drag/Drop </summary>//<param name= "Dragpos" ></param> void Ondr        Agduan (Vector3 dragpos) {Vector3 Direction v3 = (dragpos-firstpos). normalized;            if (direction v3! = Vector3.zero) {mjoystick. Direction = quaternion.lookrotation (Direction v3, new Vector3 (0, 0,-1));            Mjoystick. Distance = Mathf.clamp (Vector3.distance (Dragpos, Firstpos), 0, Mjoystick. Distance max);        IMGCheck.transform.localPosition = mjoystick. Direction * Vector3.forward * mjoystick. Distance;        }} public class Joystickinput {public bool isuser;        public quaternion direction;        public float distance;         public float distance Max;        public float get Force () {return distance/distance max; Public quaternion gety direction () {quaternion temp = JoyPlayerCtrl.Instance.mJoystick. Direction * quaternion .            Euler (90,0,0); Return Quaternion.euler (0,-temp.eulerangles.z, 0); }} void Ongui () {if (Mjoystick.isuser) {GUI.            Label (New Rect (10, 10, 200, 30), "direction" + Mjoystick. Direction. eulerangles.tostring ()); Gui.            Label (New Rect (10, 50, 200, 30), distance + Mjoystick. Distance); Gui.        Label (New Rect (10, 90, 200, 30), "force" + Mjoystick.get Force ()); }    }}

The scene layout structure is as follows:


Ugui Realized variable speed joystick

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.