游戏场景——游戏界面——游戏主界面
游戏界面的UI
反正就照着这样来拼就行了
写代码
新建一个文件夹
类中关联的控件
监听的事件
记录分数
更新血量
更新时间
还要加一句labTime.content.text=nowTime.ToString();
直到当前GamePanel的代码如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GamePanel : BasePanel<GamePanel>
{
//关联的按钮控件
public CustomGUILabel labScore;
public CustomGUILabel labTime;
public CustomGUIButton btnQuit;
public CustomGUIButton btnSetting;
public CustomGUITexture texHP;
//用于更新分数的变量
public int nowScore;
//血条控件的宽
public int hpW = 300;
//用于更新时间的变量
public float nowTime;
void Start()
{
Cursor.lockState = CursorLockMode.Confined;
//监听事件
btnQuit.clickEvent += () =>
{
};
btnSetting.clickEvent += () =>
{
};
}
void Update()
{
//更新时间
nowTime += Time.deltaTime;
labTime.content.text = nowTime.ToString() + "秒";
}
/// <summary>
/// 用于更新分数的函数
/// </summary>
/// <param name="score"></param>
public void AddScore(int score)
{
nowScore += score;
labScore.content.text = score.ToString();
}
/// <summary>
/// 更新血条的函数
/// </summary>
/// <param name="maxHP"></param>
/// <param name="hp"></param>
public void UpdateHP(int maxHP,int hp)
{
texHP.guiPos.width = (float)hp / maxHP * hpW;
}
}