zoukankan      html  css  js  c++  java
  • unity3d-游戏实战突出重围,第二天 制作血条

     

     

     1 using UnityEngine;
     2 using System.Collections;
     3 
     4 public class xt : MonoBehaviour
     5 {
     6 
     7     //红色血条
     8     public Texture2D blood_red;
     9     //黑色血条
    10     public Texture2D blood_black;
    11     //当前生命值
    12     private int HP = 100;
    13 
    14     void OnGUI()
    15     {
    16         if (GUILayout.RepeatButton("加血"))
    17         {
    18             //增加生命值
    19             if (HP < 100)
    20             {
    21                 HP++;
    22             }
    23         }
    24         if (GUILayout.RepeatButton("减血"))
    25         {
    26             //减少生命值
    27             if (HP > 0)
    28             {
    29                 HP--;
    30             }
    31         }
    32         //根据当前生命值计算红色血条显示的宽度
    33         int blood_width = blood_red.width * HP / 100;
    34         //绘制黑色血条
    35         GUI.DrawTexture(new Rect(100, 100, blood_black.width, blood_black.height), blood_black);
    36         //绘制红色血条
    37         GUI.DrawTexture(new Rect(100, 100, blood_width, blood_red.height), blood_red);
    38 
    39     }
    40 }

    资源下载

    http://pan.baidu.com/s/1dDEjy9b

  • 相关阅读:
    pythoon 学习资源
    cookie -- 添加删除
    前端技能
    jsonp 跨域2
    jsonp 跨域1
    webpy.org
    Flask 学习资源
    pip install flask 安装失败
    弹窗组价
    js中的deom ready执行的问题
  • 原文地址:https://www.cnblogs.com/nsky/p/4451314.html
Copyright © 2011-2022 走看看