UIManager.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class UIManager : MonoBehaviour {
  5. //单例
  6. public static UIManager instance;
  7. private GameObject canvas;
  8. // Use this for initialization
  9. private void Awake()
  10. {
  11. instance = this;
  12. }
  13. void Start () {
  14. canvas = GameObject.Find("Canvas");
  15. // CreatePanel("PanelStart");
  16. //点击开始按钮 界面跳转 生成飞机、石头、道具
  17. UIManager.instance.CreatePanel("PanelGame");
  18. // UIManager.instance.DestroyPanel("PanelStart");
  19. PlaneManager.instance.CreateAirPlane();
  20. CreateStone.instance.InvokeRepeating("createStone", 1f, 1f);
  21. CreateStone.instance.InvokeRepeating("createProp", 1f, 3f);
  22. }
  23. //生成panel界面
  24. public void CreatePanel(string _name)
  25. {
  26. GameObject panel = Resources.Load<GameObject>("Prefabs/"+_name);
  27. GameObject go = Instantiate(panel);
  28. go.name = _name;
  29. go.transform.SetParent(canvas.transform);
  30. //go.transform.localScale = Vector3.one;
  31. //go.transform.position = Vector3.zero;
  32. }
  33. //摧毁panel界面
  34. public void DestroyPanel(string _name)
  35. {
  36. GameObject go = canvas.transform.Find(_name).gameObject;
  37. Destroy(go);
  38. }
  39. // Update is called once per frame
  40. void Update () {
  41. }
  42. }