纳金网
标题:
游戏基础案例(二)制作血条
[打印本页]
作者:
刀锋狼
时间:
2015-2-18 00:38
标题:
游戏基础案例(二)制作血条
1.首先准备两张血条的图片,底片为黑,变化的为红
2.加血减血用GUI.RepeatButton("加血")
3.血条的比例:
public int HP;
void Start()
{
HP=100;
}
void OnGUI()
{
if(GUI.RepeatButton("加血")
{
if(HP<100)
{
HP++;
}
}
if(GUI.RepeatButton("减血")
{
if(HP>0)
{
HP--;
}
}
int blood_width = blood_red.width*HP/100;
GUI.DrawTexture(new Rect(0,100,blood_width,blood_red.height),blood_red);
}
脚本代码:
BloodProcess .cs
using UnityEngine;
using System.Collections;
public class BloodProcess : MonoBehaviour {
public Texture blood_red;
public Texture blood_black;
private int HP = 100;
void OnGUI()
{
if (GUILayout .RepeatButton("加血"))
{
if (HP<100)
{
HP++;
}
}
if (GUILayout .RepeatButton("减血"))
{
if (HP>0)
{
HP--;
}
}
int blood_width = blood_red.width * HP / 100;
GUI.DrawTexture(new Rect(100, 100, blood_black.width, blood_black.height),blood_black);
GUI.DrawTexture(new Rect(100, 100, blood_width, blood_red.height), blood_red);
}
}
复制代码
欢迎光临 纳金网 (http://old.narkii.com/club/)
Powered by Discuz! X2.5