接續D14的文章,我們需要先把Monster
的血條做出來,然後再參考D16的技能設計把技能時做出來。
先把Monster
的血條做出來
然後讓ChatGPT幫我寫技能的模板,我這裡想用interface寫
幫我用interface寫一個技能的模板,參考先前法想的四個範例寫出code
我們可以新增一個Skill.cs
的script把下面的code複製進去。
public interface ISkill
{
string SkillName { get; }
int ManaCost { get; }
int Cooldown { get; }
int CurrentCooldown { get; set; }
void UseSkill(Character target);
bool CanUseSkill(int currentMana);
}
在技能的Interface寫好後,我們再接續照著前幾天的文章寫完技能。
public class Character
{
public string Name { get; set; }
public int Health { get; set; }
public int Mana { get; set; }
public Character(string name, int health, int mana)
{
Name = name;
Health = health;
Mana = mana;
}
public void TakeDamage(int damage)
{
Health -= damage;
if (Health < 0) Health = 0;
Debug.Log($"{Name} takes {damage} damage. Health is now {Health}.");
}
public void Heal(int amount)
{
Health += amount;
if (Health > 100) Health = 100; // 假設最大血量為 100
Debug.Log($"{Name} heals {amount}. Health is now {Health}.");
}
public void UseMana(int amount)
{
Mana -= amount;
if (Mana < 0) Mana = 0;
Debug.Log($"{Name} uses {amount} mana. Mana is now {Mana}.");
}
}