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 {
- public List <VerifyChecked> _addCount;
- [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 int SuccessfulCount = 0;
- 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 (Input.GetKeyDown(KeyCode.R)){
- Restart();
- RandomPlace ();
- }
- 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 (_addCount [0].addCount == false) {
- SuccessfulCount += 1;
- }
- _addCount [0].addCount = true;
- break;
- case ("Item (1)"):
- if (_addCount [1].addCount == false) {
- SuccessfulCount += 1;
- }
- _addCount [1].addCount = true;
- break;
- case ("Item (2)"):
- if (_addCount [2].addCount == false) {
- SuccessfulCount += 1;
- }
- _addCount [2].addCount = true;
- break;
- case ("Item (3)"):
- if (_addCount [3].addCount == false) {
- SuccessfulCount += 1;
- }
- _addCount [3].addCount = true;
- break;
- case ("Item (4)"):
- if (_addCount [4].addCount == false) {
- SuccessfulCount += 1;
- }
- _addCount [4].addCount = true;
- break;
- case ("Item (5)"):
- if (_addCount [5].addCount == false) {
- ErrorsCount += 1;
- }
- _addCount [5].addCount = true;
- break;
- case ("Item (6)"):
- if (_addCount [6].addCount == false) {
- ErrorsCount += 1;
- }
- _addCount [6].addCount = true;
- break;
- case ("Item (7)"):
- if (_addCount [7].addCount == false) {
- ErrorsCount += 1;
- }
- _addCount [7].addCount = true;
- break;
- case ("Item (8)"):
- if (_addCount [8].addCount == false) {
- ErrorsCount += 1;
- }
- _addCount [8].addCount = true;
- break;
- case ("Item (9)"):
- if (_addCount [9].addCount == false) {
- ErrorsCount += 1;
- }
- _addCount [9].addCount = true;
- break;
- }
- }
- }
- }
- }
- public void Reseter(){
- scoreTime = 1200;
- seconds = oldTime;
- ErrorsCount = 0;
- SuccessfulCount = 0;
- RunTime = false;
- EndTime = false;
- for (int i = 0; i < _addCount.Count; i++){
- _addCount [i].addCount = 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