Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class TimerGameV1 : MonoBehaviour {
- [Header("Таймер")]
- public Text time;
- public float seconds = 10;
- public float endTime;
- public bool reverse = false;
- [Header("Очки")]
- public Text textScore;
- public float scoreTime = 1200;
- [Header("Имя Игрока")]
- public InputField EnterName;
- public Text NamePlayer;
- [Header("Текст-подсказка")]
- public Text InfoText;
- [Header("Кубики")]
- public GameObject [] GameModels;
- [Header("Объекты для включения/выключения")]
- public GameObject [] GamePanels;
- public GameObject [] OtherObjects;
- string nameObj;
- private bool Check_Verno1 = false;
- private bool Check_Verno2 = false;
- private bool Check_Verno3 = false;
- private bool Check_Verno4 = false;
- private bool Check_Verno5 = false;
- private int SuccessfulCount = 0;
- private bool Check_NeVerno1 = false;
- private bool Check_NeVerno2 = false;
- private bool Check_NeVerno3 = false;
- private bool Check_NeVerno4 = false;
- private bool Check_NeVerno5 = false;
- private int ErrorsCount = 0;
- private int ScoreTime;
- private float privatetime;
- private bool EndTime = false;
- private bool RunTime = false;
- private float oldTime;
- public Vector3 [] GameModelsPosition;
- public Vector3[] mixArray;
- void Start(){
- oldTime = seconds;
- InfoText.text = "";
- for (int i = 0; i < GameModels.Length + 1; i++){
- GameModelsPosition = new Vector3[i];
- }
- for (int i = 0; i < GameModels.Length; i++){
- GameModelsPosition [i] = GameModels [i].transform.localPosition;
- }
- }
- Vector3 [] Mix (Vector3 [] num){
- for (int i = 0; i < num.Length; i++) {
- Vector3 currentValue = num [i];
- int randomIndex = Random.Range (i, num.Length);
- num [i] = num [randomIndex];
- num [randomIndex] = currentValue;
- }
- return num;
- }
- void Update () {
- if (RunTime) {
- if (reverse) {
- endTime = 0;
- if (seconds <= endTime) {
- seconds = 0;
- FunctionEndTime ();
- } else {
- seconds -= Time.deltaTime;
- }
- }
- else {
- if (seconds >= endTime){
- seconds = endTime;
- FunctionEndTime ();
- } else {
- seconds += Time.deltaTime;
- }
- }
- time.text = string.Format ("{0:00}:{1:00}", (int)seconds / 60, (int)seconds % 60);
- scoreTime = scoreTime - (Time.deltaTime * 10);
- ScoreTime = (int)(scoreTime);
- textScore.text = ScoreTime.ToString ();
- if (SuccessfulCount > 3) {
- InfoText.text = "";
- }
- }
- if (Input.GetMouseButtonDown(0))
- {
- RaycastHit hit;
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out hit, 100f))
- {
- if (hit.transform.GetComponent<Rigidbody> () != null) {
- nameObj = hit.transform.gameObject.name;
- Debug.Log (nameObj);
- switch (nameObj) {
- case ("Item (0)"):
- if (Check_Verno1 == false) {
- SuccessfulCount += 1;
- }
- Check_Verno1 = true;
- if (Check_Verno1 == true) {
- Debug.Log ("Верно");
- }
- break;
- case ("Item (1)"):
- if (Check_Verno2 == false) {
- SuccessfulCount += 1;
- }
- Check_Verno2 = true;
- if (Check_Verno2 == true) {
- Debug.Log ("Верно");
- }
- break;
- case ("Item (2)"):
- if (Check_Verno3 == false) {
- SuccessfulCount += 1;
- }
- Check_Verno3 = true;
- if (Check_Verno3 == true) {
- Debug.Log ("Верно");
- }
- break;
- case ("Item (3)"):
- if (Check_Verno4 == false) {
- SuccessfulCount += 1;
- }
- Check_Verno4 = true;
- if (Check_Verno4== true) {
- Debug.Log ("Верно");
- }
- break;
- case ("Item (4)"):
- if (Check_Verno5 == false) {
- SuccessfulCount += 1;
- }
- Check_Verno5 = true;
- if (Check_Verno5 == true) {
- Debug.Log ("Верно");
- }
- break;
- case ("Item (5)"):
- if (Check_NeVerno1 == false) {
- ErrorsCount += 1;
- }
- Check_NeVerno1 = true;
- if (Check_NeVerno1 == true) {
- Debug.Log ("НЕверно");
- }
- break;
- case ("Item (6)"):
- if (Check_NeVerno2 == false) {
- ErrorsCount += 1;
- }
- Check_NeVerno2 = true;
- if (Check_NeVerno2 == true) {
- Debug.Log ("НЕверно");
- }
- break;
- case ("Item (7)"):
- if (Check_NeVerno3 == false) {
- ErrorsCount += 1;
- }
- Check_NeVerno3 = true;
- if (Check_NeVerno3 == true) {
- Debug.Log ("НЕверно");
- }
- break;
- case ("Item (8)"):
- if (Check_NeVerno4 == false) {
- ErrorsCount += 1;
- }
- Check_NeVerno4 = true;
- if (Check_NeVerno4 == true) {
- Debug.Log ("НЕверно");
- }
- break;
- case ("Item (9)"):
- if (Check_NeVerno5 == false) {
- ErrorsCount += 1;
- }
- Check_NeVerno5 = true;
- if (Check_NeVerno5 == true) {
- Debug.Log ("НЕверно");
- }
- break;
- }
- }
- }
- }
- }
- public void Reseter(){
- scoreTime = 1200;
- seconds = oldTime;
- ErrorsCount = 0;
- SuccessfulCount = 0;
- RunTime = false;
- EndTime = false;
- Check_Verno1 = false;
- Check_Verno2 = false;
- Check_Verno3 = false;
- Check_Verno4 = false;
- Check_Verno5 = false;
- Check_NeVerno1 = false;
- Check_NeVerno2 = false;
- Check_NeVerno3 = false;
- Check_NeVerno4 = false;
- Check_NeVerno5 = false;
- }
- public void RandomPlace(){
- mixArray = Mix (GameModelsPosition);
- for (int i = 0; i <= 9; i++) {
- Vector3 randomObjectPosition = GameModelsPosition[i];
- GameModels[i].transform.localPosition = new Vector3(randomObjectPosition.x,randomObjectPosition.y, randomObjectPosition.z);
- }
- }
- public void CloseGame(){
- OtherObjects[2].SetActive(true);
- OtherObjects[3].SetActive(false);
- GamePanels[1].SetActive (false);
- }
- public void OnGame(){
- GamePanels[0].SetActive (true);
- Reseter ();
- }
- public void Restart(){
- GamePanels[2].SetActive (true);
- GamePanels[3].SetActive (false);
- Reseter ();
- RunTime = true;
- }
- public void OpenLeaderBoardAffterGame(){
- GamePanels[4].SetActive (false);
- GamePanels[5].SetActive (true);
- Reseter();
- }
- public void UpdatedScoreName(){
- string username = EnterName.text;
- Highscores.AddNewHighscore (username, ScoreTime);
- }
- public void FunctionClose(){
- GamePanels [4].SetActive (false);
- }
- public void FunctionEndTime(){
- EndTime = true;
- if (EndTime) {
- RunTime = false;
- GamePanels [3].SetActive (true);
- GamePanels [2].SetActive (false);
- OtherObjects[0].SetActive(true);
- }
- }
- public void Rename(){
- GamePanels[0].SetActive (true);
- GamePanels[1].SetActive (false);
- }
- public void EnterNameForm(){
- string username = EnterName.text;
- if (EnterName.text == "") {
- Debug.Log ("Пожалуйста введит ваше имя");
- } else {
- NamePlayer.text = "Здравствуй " + "<b><color=#ffa500ff>"+ EnterName.text+ "</color></b>" + "!";
- GamePanels[0].SetActive (false);
- GamePanels[1].SetActive (true);
- }
- }
- public void StartGame(){
- GamePanels[1].SetActive (false);
- GamePanels[2].SetActive (true);
- RunTime = true;
- }
- public void OpenLeaderBoard(){
- GamePanels[1].SetActive (false);
- GamePanels[5].SetActive (true);
- }
- public void CloseLeaderBoard(){
- GamePanels[5].SetActive (false);
- GamePanels[1].SetActive (true);
- }
- public void OutShip(){
- if (ErrorsCount >= 4) {
- RunTime = false;
- GamePanels [3].SetActive (true);
- GamePanels [2].SetActive (false);
- OtherObjects [0].SetActive (false);
- OtherObjects [1].SetActive (true);
- }
- if (SuccessfulCount >=4 && ErrorsCount < 4) {
- RunTime = false;
- GamePanels [2].SetActive (false);
- GamePanels [4].SetActive (true);
- UpdatedScoreName ();
- }
- if (SuccessfulCount <= 3) {
- InfoText.text = "Выбрано мало вещей!";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement