Show in inspector other class properties

Hi,

First of all, sorry if similar topics exists, but I did not find what I need. I think my case is more specific.

I’m creating a simple RPG and i’m stuck with an issue. I want to have properties in the inspector but not from the main class, i want properties from another class wich is used as a variable in the main class.

Example:

using UnityEngine;
public class Character : MonoBehaviour
{
    #region VARIABLES MEMBRES
    private string _name;
    private string _class;
    private Bar _health;//HERE
    public enum EnumType { Ally, Neutral, Ennemy };
    public EnumType characterType;

    #endregion

    #region PROPRIETES

    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
    public string Class
    {
        get { return _class; }
        set { _class = value; }
    }
    public Bar Health//HERE
    {
        get { return _health; }
        set { _health = value; }
    }

    #endregion

    #region CONSTRUCTEUR

    public Character(string n)
    {
        Name = n;
        Class = "Human";
        Health = new Bar();
        characterType = EnumType.Neutral;
    }

    #endregion
}

Here you can see that i use a property “Health” for my _health variable, which is a “Bar”.

Here is the Bar Class:

using UnityEngine;

public class Bar : MonoBehaviour
{
    #region VARIABLES MEMBRES

    private int _maxValue;//HERE
    private int _currentValue;

    #endregion

    #region PROPRIETES

    public int MaxValue//HERE
    {
        get { return _maxValue; }
        set { _maxValue = value; }
    }

    public int CurrentValue
    {
        get { return _currentValue; }
        set { _currentValue = value; }
    }

    #endregion

    #region CONSTRUCTEUR

    public Bar()
    {
        MaxValue = 100;
        CurrentValue = MaxValue;
    }
    public Bar(int v)
    {
        MaxValue = v;
        CurrentValue = MaxValue;
    }

    #endregion
}

And I want, when i drag my Character script on a GameObject, that my “MaxValue” variable from my “Bar” Class is shown in the inspector.

I have no idea how to do it, i tried so many times last night and I searched a lot online but i found nothing usefull… I really hope you can help me. And I hope I’m understandable.

Thanks for your time folks!

edit: here is a screen shot of what I have (Character) and what I want (Character Test), hope it is usefull.
149177-unityinspector.png

Ok I apparently just found the solution. I didn’t tested it yet, but it appear to work in the inspector.
We just need to add [Serializable] to the class and [SerializeField] to its variables.

[Serializable]
public class Bar{
    [SerializeField] private int _maxValue;
    [SerializeField] private int _currentValue;

    public int MaxValue
    {
        get { return _maxValue; }
        set { _maxValue = value; }
    }
    public int CurrentValue
    {
        get { return _currentValue; }
        set { _currentValue = value; }
    }
}

Then add again [SerializeField] but in the variable declaration in the class Character:

using UnityEngine;
public class Character : MonoBehaviour
{
    [SerializeField] private Bar _health;


    public Bar Health
    {
        get { return _health; }
        set { _health = value; }
    }
}

And here is how it shows in the inspector (with others variables i use):
149178-unityinspector.png

I really hope it will help someone. Sorry for the self-solving forum.
Thanks again to you @Hellium for your correction.
Have a nice day folks!

I can’t seem to get it to work for me.