3-19 Self Heal Special Ability Challenge
今天要來製作補血技能啦!本章先簡單帶大家製作能發動的補血技能,後面會再補上粒子特效跟快捷鍵的教學。首先,在觀看本章之前,要先有其他文章的積累才行,有需要的話請先看看下列文章唷:
首先在Special Abilities資料夾中新增一個資料夾,取名為Self Heal。
於Self Heal資料夾內新增兩個Script,SelfHealBehaviour跟SelfHealConfig。
SelfHealBehaviour.cs:
SelfHealConfig.cs:
大家應該會注意到在SelfHealBehaviour.cs中的Use方法,使用了player.AdjustHealth (-config.GetExtraHealth ()); 因為我將原本Player.cs的TakeDamage方法改名為AdjustHealth,為了在語義上跟補血技能相符合才更名,畢竟總不能呼叫TakeDamage方法卻讓玩家補血吧?使用『調整血量』這個稱呼更契合受傷跟補血兩種情境,請大家如要改名可以使用開發工具的Refactor功能,程式碼的其他地方都會跟著改唷。
寫好程式碼後,便可以在Self Heal資料夾中按右鍵,選擇Create/RPG/Special Ability/Self Heal來新增技能,方便吧!
將新技能Self Heal L1拉到Player的第一個技能欄位吧,因為目前遊戲設計上是透過滑鼠按右鍵施放第一個技能,所以測試時會有這個限制,後面再來製作快捷鍵施放技能的方法。

接下來試玩遊戲看看吧!先讓怪物打到低血量。
趕快按右鍵施放補血技能!
3-9 Special Abilities System Overview
3-10 Create An Area Of Effect Ability
首先在Special Abilities資料夾中新增一個資料夾,取名為Self Heal。
於Self Heal資料夾內新增兩個Script,SelfHealBehaviour跟SelfHealConfig。
SelfHealBehaviour.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Core;
namespace RPG.Character{
public class SelfHealBehaviour : MonoBehaviour, ISpecialAbility {
SelfHealConfig config;
Player player;
void Start(){
player = GetComponent ();
}
public void SetConfig(SelfHealConfig config){
this.config = config;
}
public void Use(AbilityParams useParams){
player.AdjustHealth (-config.GetExtraHealth ());
}
}
}
SelfHealConfig.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RPG.Character{
[CreateAssetMenu(menuName= ("RPG/Special Ability/Self Heal"))]
public class SelfHealConfig : SpecialAbilityConfig {
[Header("Self Heal Specific")]
[SerializeField] float extraHealth = 5f;
public override ISpecialAbility AddComponent (GameObject gameObjectAttachTo){
var behaviourComponent = gameObjectAttachTo.AddComponent ();
behaviourComponent.SetConfig (this);
return behaviourComponent;
}
public float GetExtraHealth(){
return extraHealth;
}
}
}
大家應該會注意到在SelfHealBehaviour.cs中的Use方法,使用了player.AdjustHealth (-config.GetExtraHealth ()); 因為我將原本Player.cs的TakeDamage方法改名為AdjustHealth,為了在語義上跟補血技能相符合才更名,畢竟總不能呼叫TakeDamage方法卻讓玩家補血吧?使用『調整血量』這個稱呼更契合受傷跟補血兩種情境,請大家如要改名可以使用開發工具的Refactor功能,程式碼的其他地方都會跟著改唷。
寫好程式碼後,便可以在Self Heal資料夾中按右鍵,選擇Create/RPG/Special Ability/Self Heal來新增技能,方便吧!
自己調整一下技能的能量消耗跟補血值,但目前還沒有特效。
將新技能Self Heal L1拉到Player的第一個技能欄位吧,因為目前遊戲設計上是透過滑鼠按右鍵施放第一個技能,所以測試時會有這個限制,後面再來製作快捷鍵施放技能的方法。

接下來試玩遊戲看看吧!先讓怪物打到低血量。
趕快按右鍵施放補血技能!






留言
張貼留言