12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class LoadManager : MonoBehaviour
- {
- // Start is called before the first frame update
- //public GameObject loadGame;
- public Scrollbar myScrollbar;
- //public Text text;
- void Start()
- {
- // 设置Scrollbar的值从0变到1
- StartCoroutine(AnimateScrollbar());
- }
- IEnumerator AnimateScrollbar()
- {
- // 设置Scrollbar的value从0开始
- myScrollbar.size = 0;
- // 计时5秒
- float duration = 5f;
- float elapsedTime = 0;
- while (elapsedTime < duration)
- {
- // 更新已过去的时间
- elapsedTime += Time.deltaTime;
- // 计算Scrollbar的新value值
- float newValue = Mathf.Clamp01(elapsedTime / duration);
- //text.text = Mathf.FloorToInt(newValue *100) + "%";
- // 更新Scrollbar的value
- myScrollbar.size = newValue;
- // 等待下一帧
- yield return null;
- }
- // 确保Scrollbar的value最终设置为1
- myScrollbar.size = 1;
- SceneManager.LoadScene("Home");
- }
- }
|