今天的文章要來把之前的寫好得技能實做到Button
的物件讓他可以在遊戲裡實際被使用。
我們先新增一個Button
在之前做好的下面,我比較喜歡用舊的按鈕,不然也可以用上面的Button-TextMeshPro
。
再把Button
下面的Text
刪掉,我們之後是要用圖片就先不用文字了。這裡可以看到滑鼠移到做好的Button
上會有反饋了。
把之前設計的技能讓ChatGPT實做出來。
參考先前想法的四個範例寫出code
public class FlameImpact : ISkill
{
public string SkillName => "Flame Impact";
public int ManaCost => 12;
public int Cooldown => 3;
public int CurrentCooldown { get; set; } = 0;
public void UseSkill(Character target)
{
if (CurrentCooldown == 0)
{
int damage = 20;
target.TakeDamage(damage);
target.UseMana(ManaCost);
CurrentCooldown = Cooldown;
Debug.Log($"{SkillName} hits {target.Name} for {damage} fire damage.");
}
else
{
Debug.Log($"{SkillName} is on cooldown for {CurrentCooldown} more turns.");
}
}
public bool CanUseSkill(int currentMana)
{
return currentMana >= ManaCost && CurrentCooldown == 0;
}
}
public class FlameImpact : ISkill
{
public string SkillName => "Flame Impact";
public int ManaCost => 12;
public int Cooldown => 3;
public int CurrentCooldown { get; set; } = 0;
public void UseSkill(Character target)
{
if (CurrentCooldown == 0)
{
int damage = 20;
target.TakeDamage(damage);
target.UseMana(ManaCost);
CurrentCooldown = Cooldown;
Debug.Log($"{SkillName} hits {target.Name} for {damage} fire damage.");
}
else
{
Debug.Log($"{SkillName} is on cooldown for {CurrentCooldown} more turns.");
}
}
public bool CanUseSkill(int currentMana)
{
return currentMana >= ManaCost && CurrentCooldown == 0;
}
}
public class ThunderChain : ISkill
{
public string SkillName => "Thunder Chain";
public int ManaCost => 18;
public int Cooldown => 5;
public int CurrentCooldown { get; set; } = 0;
public void UseSkill(Character target)
{
if (CurrentCooldown == 0)
{
int primaryDamage = 15;
int secondaryDamage = 10;
target.TakeDamage(primaryDamage);
// 假設有其他敵人可以被擊中
// Implement secondary targets for the chain effect
target.UseMana(ManaCost);
CurrentCooldown = Cooldown;
Debug.Log($"{SkillName} strikes {target.Name} for {primaryDamage} lightning damage, and chains to others.");
}
else
{
Debug.Log($"{SkillName} is on cooldown for {CurrentCooldown} more turns.");
}
}
public bool CanUseSkill(int currentMana)
{
return currentMana >= ManaCost && CurrentCooldown == 0;
}
}
public class ShadowCurse : ISkill
{
public string SkillName => "Shadow Curse";
public int ManaCost => 14;
public int Cooldown => 3;
public int CurrentCooldown { get; set; } = 0;
public void UseSkill(Character target)
{
if (CurrentCooldown == 0)
{
int damage = 15;
target.TakeDamage(damage);
target.UseMana(ManaCost);
CurrentCooldown = Cooldown;
Debug.Log($"{SkillName} curses {target.Name}, dealing {damage} shadow damage and reducing their attack.");
}
else
{
Debug.Log($"{SkillName} is on cooldown for {CurrentCooldown} more turns.");
}
}
public bool CanUseSkill(int currentMana)
{
return currentMana >= ManaCost && CurrentCooldown == 0;
}
}