Loading.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. public class Loading : MonoBehaviour {
  7. [SerializeField]
  8. private float speed;
  9. [SerializeField]
  10. private float currentAmount;
  11. public Image Loadbar;
  12. public Text Loadtext;
  13. //public GameObject player;
  14. bool isgamestart;
  15. float ingameTime = 2;
  16. void Awake () {
  17. isgamestart = false;
  18. //player.transform.position = new Vector3(-79, 10.6f, -92);
  19. currentAmount = 0;
  20. }
  21. // Update is called once per frame
  22. void Update () {
  23. if (currentAmount < 100)
  24. {
  25. //player.GetComponent<Animator>().SetBool("IsWalking", true);
  26. currentAmount += speed * Time.deltaTime;
  27. Loadtext.text = ((int)currentAmount).ToString() + "%";
  28. //Vector3 pos = player.transform.position;
  29. //pos.x = -79 + 16.5f * (currentAmount / 100);
  30. //player.transform.position = pos;
  31. }
  32. if ((int)currentAmount == 100 && !isgamestart) {
  33. //player.GetComponent<Animator>().SetTrigger("Die");
  34. isgamestart = true;
  35. }
  36. Loadbar.fillAmount = currentAmount / 100;
  37. if(isgamestart)
  38. {
  39. ingameTime -= Time.deltaTime;
  40. if (ingameTime <= 0) SceneManager.LoadScene("main");
  41. }
  42. }
  43. }