Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Dynamic Skill/Ability System

Discussion in 'Scripting' started by Collin_Patrick, Jan 27, 2018.

  1. Collin_Patrick

    Collin_Patrick

    Joined:
    Sep 24, 2016
    Posts:
    83
    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:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System.Linq;
    5.  
    6. public abstract class Skill : ScriptableObject{
    7.  
    8.     public string skillName;
    9.     public string skillDesc;
    10.  
    11.     public int cooldown;
    12.  
    13.     public enum Element
    14.     {
    15.         None,
    16.         Fire,
    17.         Water,
    18.         Earth,
    19.         Electic,
    20.         Wind,
    21.         Dark,
    22.         Holy
    23.     }
    24.     public Element element;
    25.  
    26.     public abstract void UseSkill();
    27.  
    28.     public SkillRune[] levelRunes;
    29.     private SkillRune currentLevelRune;
    30.  
    31.     public void setLevelRune(SkillRune rune)
    32.     {
    33.         currentLevelRune = rune;
    34.         if (currentLevelRune.skillMods.Contains(SkillRune.SkillModifiers.DamageElement))
    35.         {
    36.             element = currentLevelRune.element;
    37.         }
    38.     }
    39. }
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5.  
    6.  
    7. [CreateAssetMenu(menuName = "Skills/CombatSkill")]
    8. public class CombatSkill : Skill {
    9.  
    10.     public override void UseSkill()
    11.     {
    12.         setLevelRune(levelRunes[0]);
    13.  
    14.         Debug.Log(skillName + "\nDecription: " + skillDesc + "\nCooldown: " + cooldown + "\nElement: " + element);
    15.     }
    16. }
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [CreateAssetMenu(menuName = "Skills/Rune")]
    6. public class SkillRune : ScriptableObject {
    7.  
    8.     public enum SkillModifiers
    9.     {
    10.         Cooldown,
    11.         DamageElement
    12.     }
    13.     public SkillModifiers[] skillMods;
    14.  
    15.     public Skill.Element element;
    16. }
    Put this on a gameobject
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class SkillTest : MonoBehaviour {
    6.  
    7.     //public Skill worldSkill;
    8.     public Skill combatSkill;
    9.     //public Skill fieldSkill;
    10.  
    11.     //private Skill worldSkillEdit;
    12.     private Skill combatSkillEdit;
    13.     //private Skill fieldSkillEdit;
    14.     // Use this for initialization
    15.     void Start () {
    16.         InstanceSkills();
    17.  
    18.         //worldSkillEdit.UseSkill();
    19.         combatSkillEdit.UseSkill();
    20.         //fieldSkillEdit.UseSkill();
    21.     }
    22.  
    23.     private void InstanceSkills()
    24.     {
    25.         //worldSkillEdit = ScriptableObject.Instantiate(combatSkill);
    26.         combatSkillEdit = ScriptableObject.Instantiate(combatSkill);
    27.         //fieldSkillEdit = ScriptableObject.Instantiate(combatSkill);
    28.     }
    29. }
     
  2. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    As a good rule to follow: If it works move on, if you have a better idea then work that out. The community isn't going to be able to really help with this as its really down to a design decision. Your code looks fine, not too messy really. Skill systems are never going to be easy.

    One of the things we need to understand about game development is that, the first iteration of your code probably isn't going to be the best. As the project evolves the code changes to suit game mechanics, so its a good idea to not spend too much time trying to refine something that might not even be there in the end. Once a mechanic is finalized THEN you refine it.
     
    Deleted User likes this.
  3. Collin_Patrick

    Collin_Patrick

    Joined:
    Sep 24, 2016
    Posts:
    83
    True, but coming from the perspective of someone still learning how to program and design games, this kind of information is invaluable.