unity3d--Personal game car control in game

Source: Internet
Author: User

2015/08/25///////////////

by xbw/////////////////////

Environmental unity4.6.1///////////

Finally finished the parking game, first look at

This game, is to collect more than three nitrogen in the circuit, and then back to the starting point, in the car damage to complete even if victory, we only do the Android version, with the gyroscope control the car's forward and left and right, Collision detection and UI I wrote in the Control.cs, directly hanging in the traffic jam, where the car tag for player, the tag of nitrogen for Danqi, the following directly on the code;

Using unityengine;using System.collections;public class control:monobehaviour{//Use this for initialization priv    ate int danqi = 0;    private float life = 100;    private int right = 1;    private int jieshu = 1;    Public Guiskin Guiskin;    Public Guiskin GUIskin2;    Public texture2d IMG1;    Public texture2d Img2; void Ontriggerenter (Collider other) {if (Other.gameObject.tag = = "Danqi") {Destroy (Other.gam            Eobject);                    danqi++; }} void Start () {}//update is called once per frame void Update () {if (transform. position.x > 138 && transform.position.x < 139 && transform.position.z > 151 && Transform            . position.z<154 && Danqi >= 3) {right = 0;            Destroy (Gameobject.findgameobjectwithtag ("Player"));                    Time.timescale = 0;    } Life-=time.deltatime * 0.5f; } void Ongui ()   {Guistyle go = new Guistyle ();        Go.fontsize = 30;        Go.normal.textColor = new Color (0, 0, 0);        Gui.skin = Guiskin; Gui.        Drawtexture (New Rect (Screen.width * 0.01f, Screen.height * 0.02f, Screen.width * 0.1f, Screen.height * 0.15f), IMG1); Gui.        Drawtexture (New Rect (Screen.width * 0.72f, Screen.height * 0.02f, Screen.width * 0.1f, Screen.height * 0.15f), IMG2); Gui. Label (New Rect (Screen.width * 0.8f, Screen.height * 0.1f, 100, 100), "nitrogen" + Danqi.        ToString (), go); Gui. Label (New Rect (Screen.width * 0.1f, Screen.height * 0.1f, 100, 100), "corrupted" + life.        ToString (), go);        Gui.skin = GUIskin2; if (GUI. Button (New Rect (Screen.width-screen.width * 0.3f, Screen.height-screen.height * 0.15f, Screen.width * 0.3f, Screen.hei        Ght * 0.15f), "try Again") {Application.loadlevel (application.loadedlevelname); } if (GUI. Button (New Rect (0, Screen.height-screen.height * 0.15f, Screen.width * 0.3f, Screen.height * 0.15f), "Do not want to play") {Application.loadlevel ("menu"); }//if (GUI. button (new Rect (Screen.width-screen.width * 0.2f, screen.height*0.4f, Screen.width * 0.2f, Screen.height * 0.1f), "Hanging +" ))//{//Gameobject.findgameobjectwithtag ("Player"). Getcomponent<wheelsuspension_script> ().        springlength+=0.1f;            } if (life<=0) {Gui.skin = Guiskin; Gui.            Label (New Rect (Screen.width * 0.4f, Screen.height * 0.3f, +), "You Lose", go);            Time.timescale = 0;            Gui.skin = GUIskin2; if (GUI.            button (new Rect (Screen.width * 0.35f, Screen.height * 0.4f, Screen.width * 0.3f, Screen.height * 0.15f), "Try Again"))            {Application.loadlevel (application.loadedlevelname); } if (GUI.            button (new Rect (Screen.width * 0.35f, Screen.height * 0.6f, Screen.width * 0.3f, Screen.height * 0.15f), "Return to main Menu") {Application.loadlevel ("Menu ");            }} if (right = = 0) {Gui.skin = Guiskin; Gui.            Label (New Rect (Screen.width * 0.4f, Screen.height * 0.3f, +), "You WIN", go);            Time.timescale = 0;            Gui.skin = GUIskin2; if (GUI.            button (new Rect (Screen.width * 0.35f, Screen.height * 0.4f, Screen.width * 0.3f, Screen.height * 0.15f), "Try Again"))            {Application.loadlevel (application.loadedlevelname); } if (GUI.            button (new Rect (Screen.width * 0.35f, Screen.height * 0.6f, Screen.width * 0.3f, Screen.height * 0.15f), "Return to main Menu")            {Application.loadlevel ("menu"); }        }    }}
So simple, there is no understanding of the place or the wrong place please leave a message to me, learn from each other

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

unity3d--Personal game car control in game

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.