Advertisement
Creativeeart

Untitled

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