TitleController.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. public class TitleController : MonoBehaviour {
  7. public GameObject titlebackground;
  8. public GameObject titleText;
  9. public Text pressKey;
  10. public Image panel;
  11. public Image Loadimage;
  12. private float BkH = 0;
  13. Color titleColor;
  14. bool isGameStart;
  15. void Start () {
  16. Time.timeScale = 1;
  17. titlebackground.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,0);
  18. titleColor = titleText.GetComponent<Text>().color;
  19. titleColor.a = 0;
  20. titleText.GetComponent<Text>().color = titleColor;
  21. panel.color = new Color(0, 0, 0, 0);
  22. StartCoroutine(PressKey());
  23. StartCoroutine(Title());
  24. }
  25. IEnumerator PressKey()
  26. {
  27. Color presskeycolor = pressKey.color;
  28. float a = 0.05f;
  29. while (true)
  30. {
  31. presskeycolor.a += a;
  32. pressKey.color = presskeycolor;
  33. if (presskeycolor.a<=0 || presskeycolor.a>=1) a = a * -1;
  34. yield return new WaitForSeconds(0.05f);
  35. }
  36. }
  37. IEnumerator Title()
  38. {
  39. while (true)
  40. {
  41. BkH = Mathf.Lerp(BkH, 200, 0.05f);
  42. titlebackground.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, BkH);
  43. if (BkH >= 190) titleColor.a += Time.deltaTime;
  44. titleText.GetComponent<Text>().color = titleColor;
  45. if (titleColor.a >= 1) break;
  46. yield return new WaitForFixedUpdate();
  47. }
  48. }
  49. // Update is called once per frame
  50. void Update () {
  51. if (Input.GetKeyDown(KeyCode.Space))
  52. {
  53. isGameStart = true;
  54. SceneController.Instacne.SwitchScene("main");
  55. }
  56. //if(isGameStart)
  57. //{
  58. // panel.color += new Color(0, 0, 0, 0.02f);
  59. // Loadimage.gameObject.SetActive(true);
  60. // Quaternion loading = Loadimage.transform.rotation;
  61. // loading.eulerAngles -= new Vector3(0, 0, 15);
  62. // Loadimage.transform.rotation = loading;
  63. // if (panel.color.a >= 1) SceneManager.LoadScene(1);
  64. //}
  65. }
  66. }