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

  • 相关阅读:
    抽象工厂模式
    外观模式
    策略模式
    状态模式
    观察者模式
    装饰者模式
    模板方法模式
    适配器模式
    中介者模式
    组合模式
  • 原文地址:https://www.cnblogs.com/niboy/p/4257241.html
Copyright © 2011-2022 走看看