Advertisement
Creativeeart

Untitled

Mar 28th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.99 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class TimerGameV1 : MonoBehaviour {
  7.     [Header("Таймер")]
  8.     public Text time;
  9.     public float seconds = 10;
  10.     public float endTime;
  11.     public bool reverse  = false;
  12.  
  13.     [Header("Очки")]
  14.     public Text textScore;
  15.     public float scoreTime = 1200;
  16.  
  17.     [Header("Имя Игрока")]
  18.     public InputField EnterName;
  19.     public Text NamePlayer;
  20.  
  21.     [Header("Текст-подсказка")]
  22.     public Text InfoText;
  23.  
  24.     [Header("Кубики")]
  25.     public GameObject [] GameModels;
  26.  
  27.     [Header("Объекты для включения/выключения")]
  28.     public GameObject [] GamePanels;
  29.     public GameObject [] OtherObjects;
  30.  
  31.     string nameObj;
  32.     private bool Check_Verno1 = false;
  33.     private bool Check_Verno2 = false;
  34.     private bool Check_Verno3 = false;
  35.     private bool Check_Verno4 = false;
  36.     private bool Check_Verno5 = false;
  37.     private int SuccessfulCount = 0;
  38.     private bool Check_NeVerno1 = false;
  39.     private bool Check_NeVerno2 = false;
  40.     private bool Check_NeVerno3 = false;
  41.     private bool Check_NeVerno4 = false;
  42.     private bool Check_NeVerno5 = false;
  43.     private int ErrorsCount = 0;
  44.     private int ScoreTime;
  45.     private float privatetime;
  46.     private bool EndTime = false;
  47.     private bool RunTime = false;
  48.     private float oldTime;
  49.     public Vector3 [] GameModelsPosition;
  50.     public Vector3[] mixArray;
  51.  
  52.  
  53.     void Start(){
  54.         oldTime = seconds;
  55.         InfoText.text = "";
  56.         for (int i = 0; i < GameModels.Length + 1; i++){
  57.             GameModelsPosition = new Vector3[i];
  58.         }
  59.         for (int i = 0; i < GameModels.Length; i++){
  60.             GameModelsPosition [i] = GameModels [i].transform.localPosition;
  61.         }
  62.  
  63.     }
  64.  
  65.     Vector3 [] Mix (Vector3 [] num){
  66.         for (int i = 0; i < num.Length; i++) {
  67.             Vector3 currentValue = num [i];
  68.             int randomIndex = Random.Range (i, num.Length);
  69.             num [i] = num [randomIndex];
  70.             num [randomIndex] = currentValue;
  71.         }
  72.         return num;
  73.     }
  74.  
  75.     void Update () {
  76.         if (RunTime) {
  77.             if (reverse) {
  78.                 endTime = 0;
  79.                 if (seconds <= endTime) {
  80.                     seconds = 0;
  81.                     FunctionEndTime ();
  82.                 } else {
  83.                     seconds -= Time.deltaTime;
  84.                 }
  85.             }
  86.             else {
  87.                 if (seconds >= endTime){
  88.                     seconds = endTime;
  89.                     FunctionEndTime ();
  90.                 } else {
  91.                     seconds += Time.deltaTime;
  92.                 }
  93.             }  
  94.             time.text = string.Format ("{0:00}:{1:00}", (int)seconds / 60, (int)seconds % 60);
  95.             scoreTime = scoreTime - (Time.deltaTime * 10);
  96.             ScoreTime = (int)(scoreTime);
  97.             textScore.text = ScoreTime.ToString ();
  98.             if (SuccessfulCount > 3) {
  99.                 InfoText.text = "";
  100.             }
  101.         }
  102.  
  103.         if (Input.GetMouseButtonDown(0))
  104.         {
  105.             RaycastHit hit;
  106.             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  107.             if (Physics.Raycast(ray, out hit, 100f))
  108.             {
  109.                 if (hit.transform.GetComponent<Rigidbody> () != null) {
  110.                     nameObj = hit.transform.gameObject.name;
  111.                     Debug.Log (nameObj);
  112.                     switch (nameObj) {
  113.                     case ("Item (0)"):
  114.                         if (Check_Verno1 == false) {
  115.                             SuccessfulCount += 1;
  116.                         }
  117.                         Check_Verno1 = true;
  118.                         if (Check_Verno1 == true) {
  119.                             Debug.Log ("Верно");
  120.                         }
  121.                     break;
  122.                     case ("Item (1)"):
  123.                         if (Check_Verno2 == false) {
  124.                             SuccessfulCount += 1;
  125.                         }
  126.                         Check_Verno2 = true;
  127.                         if (Check_Verno2 == true) {
  128.                             Debug.Log ("Верно");
  129.                         }
  130.                         break;
  131.                     case ("Item (2)"):
  132.                         if (Check_Verno3 == false) {
  133.                             SuccessfulCount += 1;
  134.                         }
  135.                         Check_Verno3 = true;
  136.                         if (Check_Verno3 == true) {
  137.                             Debug.Log ("Верно");
  138.                         }
  139.                         break;
  140.                     case ("Item (3)"):
  141.                         if (Check_Verno4 == false) {
  142.                             SuccessfulCount += 1;
  143.                         }
  144.                         Check_Verno4 = true;
  145.                         if (Check_Verno4== true) {
  146.                             Debug.Log ("Верно");
  147.                         }
  148.                         break;
  149.                     case ("Item (4)"):
  150.                         if (Check_Verno5 == false) {
  151.                             SuccessfulCount += 1;
  152.                         }
  153.                         Check_Verno5 = true;
  154.                         if (Check_Verno5 == true) {
  155.                             Debug.Log ("Верно");
  156.                         }
  157.                         break;
  158.                     case ("Item (5)"):
  159.                         if (Check_NeVerno1 == false) {
  160.                             ErrorsCount += 1;
  161.                         }
  162.                         Check_NeVerno1 = true;
  163.                         if (Check_NeVerno1 == true) {
  164.                             Debug.Log ("НЕверно");
  165.                         }
  166.                         break;
  167.                     case ("Item (6)"):
  168.                         if (Check_NeVerno2 == false) {
  169.                             ErrorsCount += 1;
  170.                         }
  171.                         Check_NeVerno2 = true;
  172.                         if (Check_NeVerno2 == true) {
  173.                             Debug.Log ("НЕверно");
  174.                         }
  175.                         break;
  176.                     case ("Item (7)"):
  177.                         if (Check_NeVerno3 == false) {
  178.                             ErrorsCount += 1;
  179.                         }
  180.                         Check_NeVerno3 = true;
  181.                         if (Check_NeVerno3 == true) {
  182.                             Debug.Log ("НЕверно");
  183.                         }
  184.                         break;
  185.                     case ("Item (8)"):
  186.                         if (Check_NeVerno4 == false) {
  187.                             ErrorsCount += 1;
  188.                         }
  189.                         Check_NeVerno4 = true;
  190.                         if (Check_NeVerno4 == true) {
  191.                             Debug.Log ("НЕверно");
  192.                         }
  193.                         break;
  194.                     case ("Item (9)"):
  195.                         if (Check_NeVerno5 == false) {
  196.                             ErrorsCount += 1;
  197.                         }
  198.                         Check_NeVerno5 = true;
  199.                         if (Check_NeVerno5 == true) {
  200.                             Debug.Log ("НЕверно");
  201.                         }
  202.                         break;
  203.  
  204.                     }
  205.                 }
  206.             }
  207.         }
  208.  
  209.     }
  210.  
  211.     public void Reseter(){
  212.         scoreTime = 1200;
  213.         seconds = oldTime;
  214.         ErrorsCount = 0;
  215.         SuccessfulCount = 0;
  216.         RunTime = false;
  217.         EndTime = false;
  218.         Check_Verno1 = false;
  219.         Check_Verno2 = false;
  220.         Check_Verno3 = false;
  221.         Check_Verno4 = false;
  222.         Check_Verno5 = false;
  223.         Check_NeVerno1 = false;
  224.         Check_NeVerno2 = false;
  225.         Check_NeVerno3 = false;
  226.         Check_NeVerno4 = false;
  227.         Check_NeVerno5 = false;
  228.     }
  229.     public void RandomPlace(){
  230.         mixArray = Mix (GameModelsPosition);
  231.         for (int i = 0; i <= 9; i++) {
  232.             Vector3 randomObjectPosition = GameModelsPosition[i];
  233.             GameModels[i].transform.localPosition = new Vector3(randomObjectPosition.x,randomObjectPosition.y, randomObjectPosition.z);
  234.         }
  235.     }
  236.  
  237.     public void CloseGame(){
  238.         OtherObjects[2].SetActive(true);
  239.         OtherObjects[3].SetActive(false);
  240.         GamePanels[1].SetActive (false);
  241.     }
  242.     public void OnGame(){
  243.         GamePanels[0].SetActive (true);
  244.         Reseter ();
  245.     }
  246.  
  247.     public void Restart(){
  248.         GamePanels[2].SetActive (true);
  249.         GamePanels[3].SetActive (false);
  250.         Reseter ();
  251.         RunTime = true;
  252.     }
  253.     public void OpenLeaderBoardAffterGame(){
  254.         GamePanels[4].SetActive (false);
  255.         GamePanels[5].SetActive (true);
  256.         Reseter();
  257.     }
  258.  
  259.     public void UpdatedScoreName(){
  260.         string username = EnterName.text;
  261.         Highscores.AddNewHighscore (username, ScoreTime);
  262.     }
  263.  
  264.     public void FunctionClose(){
  265.         GamePanels [4].SetActive (false);
  266.     }
  267.  
  268.     public void FunctionEndTime(){
  269.         EndTime = true;
  270.         if (EndTime) {
  271.             RunTime = false;
  272.             GamePanels [3].SetActive (true);
  273.             GamePanels [2].SetActive (false);
  274.             OtherObjects[0].SetActive(true);
  275.         }
  276.     }
  277.  
  278.     public void Rename(){
  279.         GamePanels[0].SetActive (true);
  280.         GamePanels[1].SetActive (false);
  281.     }
  282.     public void EnterNameForm(){
  283.         string username = EnterName.text;
  284.         if (EnterName.text == "") {
  285.             Debug.Log ("Пожалуйста введит ваше имя");
  286.         } else {
  287.             NamePlayer.text = "Здравствуй " + "<b><color=#ffa500ff>"+ EnterName.text+ "</color></b>" + "!";
  288.             GamePanels[0].SetActive (false);
  289.             GamePanels[1].SetActive (true);
  290.         }
  291.     }
  292.     public void StartGame(){
  293.         GamePanels[1].SetActive (false);
  294.         GamePanels[2].SetActive (true);
  295.         RunTime = true;
  296.     }
  297.     public void OpenLeaderBoard(){
  298.         GamePanels[1].SetActive (false);
  299.         GamePanels[5].SetActive (true);
  300.     }
  301.     public void CloseLeaderBoard(){
  302.         GamePanels[5].SetActive (false);
  303.         GamePanels[1].SetActive (true);
  304.     }
  305.     public void OutShip(){
  306.        
  307.         if (ErrorsCount >= 4) {
  308.             RunTime = false;
  309.             GamePanels [3].SetActive (true);
  310.             GamePanels [2].SetActive (false);
  311.             OtherObjects [0].SetActive (false);
  312.             OtherObjects [1].SetActive (true);
  313.         }
  314.         if (SuccessfulCount >=4 && ErrorsCount < 4) {
  315.             RunTime = false;
  316.             GamePanels [2].SetActive (false);
  317.             GamePanels [4].SetActive (true);
  318.             UpdatedScoreName ();
  319.         }
  320.         if (SuccessfulCount <= 3) {
  321.             InfoText.text = "Выбрано мало вещей!";
  322.         }
  323.     }
  324. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement