using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Runtime.Serialization.Formatters.Binary; using System.IO; public class menu : MonoBehaviour { public GUIStyle mystyle; // GUI (, ...) string score; // void Start () { StreamReader scoredata = new StreamReader (Application.persistentDataPath + "/score.gd"); // score = scoredata.ReadLine (); // scoredata.Close (); // } void Update () { } void OnGUI(){ GUI.Box (new Rect (Screen.width*0.15f, Screen.height*0.8f, Screen.width*0.7f, Screen.height*0.1f), "MAX DISTANCE:"+score,mystyle); // if (GUI.Button (new Rect (Screen.width*0.15f, Screen.height*0.25f, Screen.width*0.7f, Screen.height*0.1f), "Start game",mystyle)) // { Application.LoadLevel(1);// } if (GUI.Button (new Rect (Screen.width*0.15f, Screen.height*0.4f, Screen.width*0.7f, Screen.height*0.1f), "Exit",mystyle)) // { Application.Quit();// } } }
using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Runtime.Serialization.Formatters.Binary; using System.IO; public class moveroad : MonoBehaviour { public GUIStyle mystyle;// int f,fuelst; float score=0,speed=-0.2f,data,fuelpos;// , public GameObject block;// public GameObject block1; public GameObject block2; public GameObject block3; public GameObject fuel; bool turbotriger=false; void Start () { StreamReader scoredata = new StreamReader (Application.persistentDataPath + "/score.gd"); data = float.Parse(scoredata.ReadLine ());// scoredata.Close (); } void Update () { transform.Translate (new Vector3 (0f,speed,0f));// score = score + (speed*-10);// if (transform.position.y < -19f) // " " { transform.position=new Vector3(0f,33.4f,0f);// block.transform.position=new Vector3(10.15f,block.transform.position.y,block.transform.position.z); block1.transform.position=new Vector3(8.42f,block1.transform.position.y,block1.transform.position.z); block2.transform.position=new Vector3(6.62f,block2.transform.position.y,block2.transform.position.z); block3.transform.position=new Vector3(4.95f,block3.transform.position.y,block3.transform.position.z); fuel.transform.position=new Vector3(11.86f,fuel.transform.position.y,fuel.transform.position.z); // () f = Random.Range (0, 5);// 1- 4- switch (f) { case 0:block.transform.position=new Vector3(2.40f,block.transform.position.y,block.transform.position.z); break; case 1:block1.transform.position=new Vector3(0.90f,block1.transform.position.y,block1.transform.position.z); break; case 2:block2.transform.position=new Vector3(-0.80f,block2.transform.position.y,block2.transform.position.z); break; case 3:block3.transform.position=new Vector3(-2.35f,block3.transform.position.y,block3.transform.position.z); break; case 4: fuelst=Random.Range(0,4); if(fuelst==0){fuelpos=2.40f;} if(fuelst==1){fuelpos=0.90f;} if(fuelst==2){fuelpos=-0.80f;} if(fuelst==3){fuelpos=-2.35f;} fuel.transform.position=new Vector3(fuelpos,fuel.transform.position.y,fuel.transform.position.z); break; } if (score>data)// { StreamWriter scoredata=new StreamWriter(Application.persistentDataPath + "/score.gd");// scoredata.WriteLine(score);// scoredata.Close();// } } } void OnGUI(){ GUI.Box (new Rect (0, 0, Screen.width, Screen.height*0.05f), "Distance(m): " + score,mystyle);// } }
using UnityEngine; using System.Collections; using UnityStandardAssets.CrossPlatformInput; public class carconroller : MonoBehaviour { void Start () { } public void Update () { if (transform.rotation.z !=0) // , { Application.LoadLevel (0); } } } public void OnGUI() { if (GUI.RepeatButton (new Rect (Screen.width*0.1f, Screen.height*0.9f, Screen.width*0.2f, Screen.height*0.08f), "L")) // { if (transform.position.x > -2.4f) { transform.Translate (new Vector3 (-0.05f, 0f, 0f)); } } if (GUI.RepeatButton (new Rect (Screen.width*0.7f, Screen.height*0.9f, Screen.width*0.2f, Screen.height*0.08f), "R")) // { if (transform.position.x < 2.4f) { transform.Translate (new Vector3 (0.05f, 0f, 0f)); } } } }
using UnityEngine; using System.Collections; public class fuelscript : MonoBehaviour { public GameObject fuelall; float mytimer=100f;// // Use this for initialization void Start () { } void Update () { mytimer = 100f; mytimer -= Time.deltaTime;// if (mytimer/mytimer==1f) // 1 { fuelall.transform.position=new Vector3(fuelall.transform.position.x-0.0011f,fuelall.transform.position.y,fuelall.transform.position.z); fuelall.transform.localScale = new Vector3(fuelall.transform.localScale.x-0.001f, 1, 1); // } if (fuelall.transform.localScale.x < 0) // { Application.LoadLevel(0); } } }
using UnityEngine; using System.Collections; public class triger : MonoBehaviour { public GameObject fuel;// greenfuel // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.name == "playercar") // fuel { fuel.transform.position=new Vector3(0,fuel.transform.position.y,fuel.transform.position.z); fuel.transform.localScale = new Vector3(1, 1, 1); // fuel } } }
Source: https://habr.com/ru/post/283186/
All Articles