function OnEnable () {
Regenerate ();
}
function Regenerate () {
if (regenerateSpeed > 0.0f) {
while (enabled) {
if (Time.time > lastDamageTime + 3) {
health += regenerateSpeed;
yield;
if (health >= maxHealth) {
health = maxHealth;
enabled = false;
}
}
yield WaitForSeconds (1.0f);
}
}
}
原文:http://www.cnblogs.com/943711466qq/p/4454596.html