21402人加入学习
(187人评价)
Unity2D 官方入门案例 - Ruby's Adventure

制作完成于2020年5月5日,基于Unity2019.3

价格 免费

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);

限定第一个参数,最小值,最大值。

[展开全文]