using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class MenuManager : MonoBehaviour { public Transform vcam; public Button btnPlay; public Button btnLeaderboard; public Button btnExit; public CanvasGroup loadingCanvasGroup; public BlockProgressBar progressBar; void Awake() { loadingCanvasGroup.alpha=1f; } void Start() { btnPlay.onClick.AddListener(OnPlayClick); btnExit.onClick.AddListener(OnExitClick); StartCoroutine(LoadingScreen()); } IEnumerator LoadingScreen() { progressBar.progress = 0f; while(progressBar.progress < 1f) { progressBar.progress += 0.1f; progressBar.progress = Mathf.Clamp01(progressBar.progress); yield return new WaitForSeconds(Random.Range(0.05f, 1f)); } yield return new WaitForSeconds(0.8f); float alpha = 1f; while(alpha > 0){ alpha-=Time.deltaTime * 3f; loadingCanvasGroup.alpha = alpha; yield return null; } loadingCanvasGroup.alpha=0; loadingCanvasGroup.blocksRaycasts=false; } void OnPlayClick() { StartCoroutine(PlayCoroutine()); } IEnumerator PlayCoroutine(){ progressBar.progress = 0; float camSpeed = 0f; float speed = 50f; while(camSpeed < GameManager.movespeed){ float multiplier = Mathf.Clamp01(camSpeed / GameManager.movespeed); loadingCanvasGroup.alpha = multiplier; progressBar.progress = multiplier; camSpeed += Time.deltaTime * speed; vcam.position = new Vector3(vcam.position.x, vcam.position.y, vcam.position.z + camSpeed * Time.deltaTime); yield return null; } GameManager.Reset(); SceneManager.LoadScene("GameScene"); } void OnExitClick() { Application.Quit(); } }