I am trying to make an ability system that allows the player to customize the skills. I want to be able to dynamically alter the values within the skills such as the element of the skill when a “rune” is equipped.
I’m currently am able to do this with my current code but I feel there is a better and less messy way of going about this.
Here are my scripts:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public abstract class Skill : ScriptableObject{
public string skillName;
public string skillDesc;
public int cooldown;
public enum Element
{
None,
Fire,
Water,
Earth,
Electic,
Wind,
Dark,
Holy
}
public Element element;
public abstract void UseSkill();
public SkillRune[] levelRunes;
private SkillRune currentLevelRune;
public void setLevelRune(SkillRune rune)
{
currentLevelRune = rune;
if (currentLevelRune.skillMods.Contains(SkillRune.SkillModifiers.DamageElement))
{
element = currentLevelRune.element;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "Skills/CombatSkill")]
public class CombatSkill : Skill {
public override void UseSkill()
{
setLevelRune(levelRunes[0]);
Debug.Log(skillName + "\nDecription: " + skillDesc + "\nCooldown: " + cooldown + "\nElement: " + element);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "Skills/Rune")]
public class SkillRune : ScriptableObject {
public enum SkillModifiers
{
Cooldown,
DamageElement
}
public SkillModifiers[] skillMods;
public Skill.Element element;
}
Put this on a gameobject
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SkillTest : MonoBehaviour {
//public Skill worldSkill;
public Skill combatSkill;
//public Skill fieldSkill;
//private Skill worldSkillEdit;
private Skill combatSkillEdit;
//private Skill fieldSkillEdit;
// Use this for initialization
void Start () {
InstanceSkills();
//worldSkillEdit.UseSkill();
combatSkillEdit.UseSkill();
//fieldSkillEdit.UseSkill();
}
private void InstanceSkills()
{
//worldSkillEdit = ScriptableObject.Instantiate(combatSkill);
combatSkillEdit = ScriptableObject.Instantiate(combatSkill);
//fieldSkillEdit = ScriptableObject.Instantiate(combatSkill);
}
}