JesseEtzler's RPG Talent System in C#

Hello, JesseEtzler0 is doing new tutorial series how to make skills. It is pretty easy so far, but I was trying to make it in C# but I failed.
Simply, he made a class with variables like skillName, skillDescription etc. and then he made a new script where he made an array of this class properties, like var Skills : skills where “skills” is a name of class. Then he just simply defined these skill variables in the inspector. Is there any way how to make it in C#? I tried to make it like this:

using UnityEngine;

public class Skill {

    private string _name;
    private string _description;
    private int _requiredPoints;
    private int _addedPoints;
    private bool _hasLearnt;

    public Skill() {

        _name = "Enter name of the skill here.";
        _description = "Describe the skill here.";
        _requiredPoints = 1;
        _addedPoints = 0;
        _hasLearnt = false;
    }

    #region Getters and Setters of Skill class
    public string Name {

        get { return _name; }
        set { _name = value; }
    }

    public string Description
    {

        get { return _description; }
        set { _description = value; }
    }

    public int RequiredPoints
    {

        get { return _requiredPoints; }
        set { _requiredPoints = value; }
    }

    public int AddedPoints
    {

        get { return _addedPoints; }
        set { _addedPoints = value; }
    }

    public bool HasLearnt
    {

        get { return _hasLearnt; }
        set { _hasLearnt = value; }
    }
    #endregion
}

And then I made a new script called Skills wherein I was trying to make mentioned array of class, but everything I was trying failed.

What do you mean failed?

If this script is supposed to be attached to a game object, you should inherit from MonoBehaviour and should not set the values yourself in the constructor (unless you want something to always take a default value that the user shouldn’t change), and add a [SerializeField] attribute to the variables you want to make visible in the inspector.

If you don’t want to attach this script to a game object and instantiate it normally with new, I suggest you inject the dependencies, instead of hard-coding them in the constructor yourself. In other words, create a constructor like:

public Skill(string name, string description, float points, etc)

Let the outside world, give you what you need.

EDIT: so after some comments, it turned out that you’re trying to do something like:

public class Skills : MonoBehaviour
{
   Skill Archery = new Skill( stuff );
   Archery.Name = "Value";
}

You can’t do that in your global space. Do it somewhere like, in Awake or Start or wherever it’s relevant to you:

public class Skills : MonoBehaviour 
{
      Skill Archery;
      void Start()
      {
         Archery = new Skill("Archery", "Allows user to use ranged weapons", 1, 0, false);        
         Archery.Name = "Archery Skill";
      }
}

To be accurate, you could initialize your Skill member, but you can’t set your skill’s stuff at the global space. ie you could do:

public class Skills : MonoBehaviour 
{
      Skill Archery = new Skill("Archery", "Allows user to use ranged weapons", 1, 0, false);        

      void Start()
      {
           Archery.Name = "Archery Skill";
      }
}