12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class PanelGame : MonoBehaviour {
- //创建单例
- public static PanelGame instance;
- private Button pauseBtn;
- private Button againBtn;
- private Text score;
- public Image blood;
- private Button bigbangBtn;
- private float time;
- private void Awake()
- {
- instance = this;
- }
- // Use this for initialization
- void Start () {
- pauseBtn = transform.Find("PauseBtn").GetComponent<Button>();
- againBtn = transform.Find("AgainBtn").GetComponent<Button>();
- bigbangBtn = transform.Find("BigBangBtn").GetComponent<Button>();
- pauseBtn.onClick.RemoveAllListeners();
- pauseBtn.onClick.AddListener(pauseBtnEvent);
- againBtn.onClick.RemoveAllListeners();
- againBtn.onClick.AddListener(againBtnEvent);
- bigbangBtn.onClick.RemoveAllListeners();
- bigbangBtn.onClick.AddListener(bigbangBtnEvent);
- againBtn.gameObject.SetActive(false);
- score = transform.Find("Score").GetComponent<Text>();
- blood = transform.Find("Image/HP").GetComponent<Image>();
- }
- private void bigbangBtnEvent()
- {
- PlaneManager.instance.CreateBigBang();
- }
- //开始按钮和暂停按钮
- private void againBtnEvent()
- {
- Time.timeScale = 1;
- pauseBtn.gameObject.SetActive(true);
- againBtn.gameObject.SetActive(false);
- }
- private void pauseBtnEvent()
- {
- Time.timeScale = 0;
- againBtn.gameObject.SetActive(true);
- pauseBtn.gameObject.SetActive(false);
- }
- // Update is called once per frame
- void Update () {
- //将分数转换为字符串格式在分数文本框中显示
- score.text = ScoreManager.instance.Score.ToString();
- //解决血条清空后反向显示问题
- float num = (float)PlaneManager.instance.PlayerHP / 20.0f;
- if (num<=0)
- {
- num = 0;
- }
- blood.transform.localScale = new Vector3(num,1,1);
-
- }
-
- }
|