using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; public class ScaleToText : MonoBehaviour//frame3 0115 { public GameObject scale;//шкала //public Text altitude;//счетчик public TextMeshPro altitude;//счетчик public GameObject frame; float Y; //пердыдущее значение y float d; //коэффициент float k; //текущее значение счетчика в float bool reverse = false; //направление int min = -130;//минимальное значение счетчика int max = 6760;//максимальное значение счетчика float waitTime = 0.005f;//время для корутины [HideInInspector] public bool point = false;//нажатие на счетчик private Coroutine coroutine; private void Start() { d = 3450 / 1800f; OnK(); scaleText(); Rever(); } private void Update() { if (Y != scale.gameObject.transform.localPosition.y) { OnK(); scaleText(); Rever(); } } private void scaleText() { int ko = (int)k; if (ko >= 0) { altitude.color = Color.white; if (frame.gameObject.GetComponent()!= null) { frame.gameObject.GetComponent().EnableSprite(0); } } else { altitude.color = Color.yellow; if (frame.gameObject.GetComponent() != null) { frame.gameObject.GetComponent().EnableSprite(1); } } if (ko > 100 || ko < -100) { ko = ko / 10 * 10; } //altitude.text = ko.ToString(); altitude.SetText(ko.ToString()); } private void OnK() { Y = scale.gameObject.transform.localPosition.y; k = -Y * d + 3310f; } private void OnMouseDown()//нажатие на счетчик { point = !point; if (point) { Rever(); if (reverse) { k--; coroutine = StartCoroutine(AltNumber()); } else { k++; coroutine = StartCoroutine(AltNumber()); } } else { if(coroutine!=null)StopCoroutine(coroutine); } } private void Rever() { if (k <= min) { reverse = false; }else if(k >= max) { reverse = true; } } IEnumerator AltNumber() { while (point) { scaleText(); Y = (k - 3310f) / -d; scale.gameObject.transform.localPosition = new Vector3(scale.gameObject.transform.localPosition.x, Y, scale.gameObject.transform.localPosition.z); if (reverse) { k--; } else { k++; } Rever(); yield return new WaitForSeconds(waitTime); } } }