PanelGame.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class PanelGame : MonoBehaviour {
  7. //创建单例
  8. public static PanelGame instance;
  9. private Button pauseBtn;
  10. private Button againBtn;
  11. private Text score;
  12. public Image blood;
  13. private Button bigbangBtn;
  14. private float time;
  15. private void Awake()
  16. {
  17. instance = this;
  18. }
  19. // Use this for initialization
  20. void Start () {
  21. pauseBtn = transform.Find("PauseBtn").GetComponent<Button>();
  22. againBtn = transform.Find("AgainBtn").GetComponent<Button>();
  23. bigbangBtn = transform.Find("BigBangBtn").GetComponent<Button>();
  24. pauseBtn.onClick.RemoveAllListeners();
  25. pauseBtn.onClick.AddListener(pauseBtnEvent);
  26. againBtn.onClick.RemoveAllListeners();
  27. againBtn.onClick.AddListener(againBtnEvent);
  28. bigbangBtn.onClick.RemoveAllListeners();
  29. bigbangBtn.onClick.AddListener(bigbangBtnEvent);
  30. againBtn.gameObject.SetActive(false);
  31. score = transform.Find("Score").GetComponent<Text>();
  32. blood = transform.Find("Image/HP").GetComponent<Image>();
  33. }
  34. private void bigbangBtnEvent()
  35. {
  36. PlaneManager.instance.CreateBigBang();
  37. }
  38. //开始按钮和暂停按钮
  39. private void againBtnEvent()
  40. {
  41. Time.timeScale = 1;
  42. pauseBtn.gameObject.SetActive(true);
  43. againBtn.gameObject.SetActive(false);
  44. }
  45. private void pauseBtnEvent()
  46. {
  47. Time.timeScale = 0;
  48. againBtn.gameObject.SetActive(true);
  49. pauseBtn.gameObject.SetActive(false);
  50. }
  51. // Update is called once per frame
  52. void Update () {
  53. //将分数转换为字符串格式在分数文本框中显示
  54. score.text = ScoreManager.instance.Score.ToString();
  55. //解决血条清空后反向显示问题
  56. float num = (float)PlaneManager.instance.PlayerHP / 20.0f;
  57. if (num<=0)
  58. {
  59. num = 0;
  60. }
  61. blood.transform.localScale = new Vector3(num,1,1);
  62. }
  63. }