I’m trying to make a ScriptableObject Ability System for my grid based game.
public class Skill : ScriptableObject
{
public SkillDamageProperty[] damageProperties;
public void ApplySkill(Vector2Int position)
{
MapPositions positions = GameObject.Find("Map").GetComponent<MapPositions>();
// Damage
for (int i = 0; i < damageProperties.Length; i++)
{
Vector2Int target = position + damageProperties*.position;*
GameObject obj = positions.GetPosition(target);
if (obj == null) continue;
Stats entity = obj.GetComponent();
if (entity == null) continue;
entity.Health -= damageProperties*.damage;*
}
}
As this class is a Scriptable Object I can create multiple skills and select which positions take damage in the inspector.
----------
Beside damage, I want the skills to apply other effects to the enemies (like stunning, pushing, setting them on fire, etc). This effects would also be assigned to each skill in the inspector.
Now here’s my problem: different effects may require diferent arguments (burning requires int duration
, pushing requires Vector2Int direction
, and so on). How could I assign diferent types of arguments in the ispector?
----------
I thought about 2 ways of doing this, but both ways have problems:
- I could create a class like I did for the damageProperties and then use subclasses for each type of effect. The problem here is that subclass variables don’t show up in the inspector.
- My other Idea was to make a UnityEvent and assign one function to each effect in the inspector. Here I have 2 problems: I can only pass one argument in the inspector (and I may need more arguments for some effects) and if I pass the arguments in the inspector I cannot pass the entity that’s going to get it when I call event.Invoke();