public int maxHealth=5;//最大生命值currentHealth;//Ruby的当前生命值
currentHealth = maxHealth;
private void ChangeHealth(int amount)
{currentHealth=Mathf.Clamp(currentHealth+amount,0,maxHealth);
}
public int maxHealth=5;//最大生命值currentHealth;//Ruby的当前生命值
currentHealth = maxHealth;
private void ChangeHealth(int amount)
{currentHealth=Mathf.Clamp(currentHealth+amount,0,maxHealth);
}
public int maxHealth = 5;//最大生命值
private int currentHealth;//Ruby的当前生命值(可变)
currentHealth = maxHealth;
private void ChangeHealth(int amount)//改变生命值,增加或减少
{
currentHealth = Mathf.Clamp(currentHealth + amount, 0, maxHealth);
Debug.Log(currentHealth + "/" + maxHealth);
}
class:
{
pubic int maxHealth=5;
private int currenthealth;
}
void start()
{
current health=maxHealth
}
private void ChangeHealth(int amount)
{
currentHealth=Mathf.Clamp(current health+amount,0,maxHealth)
}
Clamp方法?
结果输出在控制台:Debug.Log(currentHealth+"/"+maxHealth)
Mathf.Clamp(a,b,c);
返回zhi类型的范围在b-c之间
Mathf.Clamp(currentHealth+amout,0,maxHeath);
限定第一个参数,最小值,最大值。