UNITY3D__ Collaborative Program

Source: Internet
Author: User

Nonsense not much to say directly on the code

usingUnityengine;usingSystem.Collections; Public classCoroutinedemos:monobehaviour { PublicTransform Targetts;  Public BOOLKispress =false;  Public BOOLIsmoreonepositon =false;  Public BOOLIslessonepositon =false; //Use this for initialization    voidStart () {} Public voidBtnkeycheck () {Startcoroutine (Keycheck (KEYCODE.A)); }         Public voidCheckpos () {Startcoroutine (Checktransform (Targetts)); }             Public voidCheckpostwo () {Startcoroutine (Checktransformtwo (Targetts)); } IEnumerator Keycheck (keycode code) { while(!kispress) {            if(Input.getkeyup (code)) {startgame ();  Break; }            yield return NULL; } Debug.Log ("Game is end"); }        voidStartgame () {kispress=true; Print ("startgame!!!!!!!!!!!!!!!!!!!"); } IEnumerator Checktransform (Transform t) { while(!Ismoreonepositon) {            if(T.position.x <0.2) {newposition ();  Break; }            yield return NULL; } Debug.Log ("Checktransform is end"); Ismoreonepositon=false; }        voidnewposition () {Ismoreonepositon=true; Print (targetts.position.x+"--newposition!!!!!!!!!!!!!!!!!!!" ); } IEnumerator Checktransformtwo (Transform t) { while(!Islessonepositon) {            if(T.position.x >4.9) {newpositiontwo ();  Break; }            yield return NULL; } Debug.Log ("Checktransformtwo is end"); Islessonepositon=false; }        voidNewpositiontwo () {Islessonepositon=true; Print (targetts.position.x+"--newpositiontwo!!!!!!!!!!!!!!!!!!!" ); }}
View Code

A total of three collaborative programs

One to detect the user pressed a key on the keyboard event

Two other events that detect the x-coordinate of a cube object greater than 4.9 or less than 0.2, respectively

Give three button click events respectively

Cooperative program fascinated, if there are errors, welcome to correct, thank you!

UNITY3D__ Collaborative Program

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.