Unity坦克大战开发全流程——游戏场景——游戏界面——游戏主界面

游戏场景——游戏界面——游戏主界面

游戏界面的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;
    }


}

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值