54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using System.Collections;
|
|
using UnityEditor.Tilemaps;
|
|
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(CanvasGroup))]
|
|
public class BackToMenuButton : MonoBehaviour
|
|
{
|
|
[Header("Появление")]
|
|
[SerializeField] float appearSpeed = 100;
|
|
[SerializeField] float appearDelay = 2;
|
|
|
|
[Header("Растворение")]
|
|
[SerializeField] float disappearSpeed = 1;
|
|
[SerializeField] float disappearDelay = 0;
|
|
|
|
CanvasGroup canvasGroup;
|
|
GameManager gm;
|
|
bool ActualState = false;
|
|
void Start()
|
|
{
|
|
canvasGroup = GetComponent<CanvasGroup>();
|
|
gm = GameManager.instance;
|
|
ActualState = gm.moveMade;
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
if (ActualState != gm.moveMade)
|
|
{
|
|
ActualState = gm.moveMade;
|
|
StopAllCoroutines();
|
|
StartCoroutine(changeState());
|
|
}
|
|
}
|
|
|
|
IEnumerator changeState()
|
|
{
|
|
//actualState true значит что ход сделан и надо убрать надпись
|
|
float speed = ActualState ? disappearSpeed : appearSpeed;
|
|
float delay = ActualState ? disappearDelay : appearDelay;
|
|
float targetAlpha = ActualState ? 0 : 1;
|
|
|
|
yield return new WaitForSeconds(delay);
|
|
while (canvasGroup.alpha != targetAlpha)
|
|
{
|
|
canvasGroup.alpha = Mathf.MoveTowards(canvasGroup.alpha, targetAlpha, Time.deltaTime * speed);
|
|
yield return null;
|
|
}
|
|
canvasGroup.alpha = targetAlpha;
|
|
}
|
|
|
|
}
|