Variable from other class always returns 0

I’m trying to call an int from another class and I’ve tried everything, from instancing to creating a new instance using the = new… Considering this is scripting and not straight up class-making i guess it’s different because it attaches to an object.

Here’s my problem, I have a really nice stat system set up, alright, not really nice, but for just starting out with unity I like it. Either way, I’m going to send you the basics of the code and see if you guys can help


public class StatHandler : MonoBehaviour {

public int stamina, strength, agility, dexterity, wisdom;
public int baseHealth, baseMana;
public int statPoints;

public bool showingStatGUI;

#region start
void Start() {
	//TODO Class Based Stats
	stamina = 10;
	strength = 10;
	agility = 10;
	dexterity = 10;
	wisdom = 10;
	baseHealth = stamina * 10;
	baseMana = wisdom * 10;
	statPoints = 100;
	showingStatGUI = false;

#region getters
public int Stamina {
	get { return stamina; }
    set { stamina = value; }

I tried using a getter this time to return the value and still have no luck, please remember that on the StatHandler itself the variables do have values, which I can edit with the gui I created.

Here’s the other part


public int stamina;
	public float healthBarLength;
	// Use this for initialization
	void Start () {
		StatHandler sh = new StatHandler();
		healthBarLength = Screen.width / 2;
		stamina = sh.Stamina;

Please note, the above was just an attempt using the setter/getters, it tossed a compiler error without creating a new StatHandler, this is really irritating and my only problem with creating many scripts.

Since you are inheriting from MonoBehavior, you can not use new,

so “StatHandler sh = new StatHandler();” is not an option.

By inheriting from MonoBehavior, you defined a unity Component for unity.

You have the option of either instantiate your class as part of the prefab object to which it is attached to:

Or add the component to an existing or newly created GameObject:

(Newly create a GameObject and add component: