Retrieving a variable with GetComponent?

So, I was told that because in my StatHandler class I was inheriting my MonoBehaviour I couldn’t use the old fashioned new StatHandler to get my integers, I was having a problem with the ints always retrieving 0 and still am, so I’m just going to upload my scripts. >_> I was told to use a script to AddComponents to my GameObject, so I’ll toss that in too, I guess.

Component.cs

using UnityEngine;
using System.Collections;

public class Component : MonoBehaviour {
	public StatHandler statHandler;
	public HealthHandler healthHandler;

	void Start () {
        statHandler = gameObject.AddComponent<StatHandler>();
		healthHandler = gameObject.AddComponent<HealthHandler>();
	}

}

StatHandler.cs

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

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;
	}
	#endregion

	#region getters
	public int Stamina {
		get { return stamina; }
        set { stamina = value; }
	}
	#endregion
	void Update() {

	}
	
	// Displays interfaces
	
	void OnGUI() {
		
		
		if(showingStatGUI) {
			showStatGUI ();
		} else {
			showStatOpenGUI();
		}
	}
	
	void showStatOpenGUI() {
		if(GUI.Button(new Rect(0, Screen.height - 50, 150, 50), "Open Stats")) {
				showingStatGUI = true;
			}
		}
			
	
	#region StatGUI	
	void showStatGUI() {
		//Close Button
		if(GUI.Button (new Rect((Screen.width / 2) +390, 20, 30, 28), "X")) { showingStatGUI = false; }
		//Background Boxes
		GUI.Box (new Rect(220, 20, (Screen.width / 2)+200, (Screen.height / 2)+200), "");
		GUI.Box (new Rect(220, 20, (Screen.width / 2)+200, 25), "Interface: Stat Points");
		
		//Base Stat Text Box
		GUI.Box (new Rect(225, 65, 155, 30), "Base Stats");
		
		//Base Stats
		GUI.Box  (new Rect(250, 105, 155, 25), "Stamina: " +stamina);
		GUI.Box  (new Rect(250, 135, 155, 25), "Strength: " +strength);
		GUI.Box  (new Rect(250, 165, 155, 25), "Agility: " +agility);
		GUI.Box  (new Rect(250, 195, 155, 25), "Dexterity: " +dexterity);
		GUI.Box  (new Rect(250, 225, 155, 25), "Wisdom: " +wisdom);
		
		// Information Boxes
		GUI.Box  (new Rect(425, 105, 315, 25), "Stamina increases your base health");
		GUI.Box  (new Rect(425, 135, 315, 25), "Strength increases your base melee damage");
		GUI.Box  (new Rect(425, 165, 315, 25), "Agility increases range based damage");
		GUI.Box  (new Rect(425, 195, 315, 25), "Dexterity increases crit rating and accuracy");
		GUI.Box  (new Rect(425, 225, 315, 25), "Wisdom increases magic damage and mana");
		
		// Spending points
		
		//Stamina
		if(GUI.Button  (new Rect(745, 105, 175, 25), "Increase Stamina by 1")) { AddStat("Stamina"); }
		//Strength
		if(GUI.Button  (new Rect(745, 135, 175, 25), "Increase Strength by 1")) { AddStat("Strength"); }
		//Agility
		if(GUI.Button  (new Rect(745, 165, 175, 25), "Increase Agility by 1")) { AddStat("Agility"); }
		//Dexterity
		if(GUI.Button  (new Rect(745, 195, 175, 25), "Increase Dexterity by 1")) { AddStat("Dexterity"); }
		//Wisdom
		if(GUI.Button  (new Rect(745, 225, 175, 25), "Increase Wisdom by 1")) { AddStat("Wisdom"); }
		
		
		// Remaining Stat Points
		GUI.Box (new Rect((Screen.width / 2) +250, 45, 155, 25), "Remaining Points: " +statPoints);
		
		
		// Base Health, Damage, Mana, etc.
	
	}
	#endregion
	
	//Adding stat points
	void AddStat(string stt) {
		if(statPoints < 1) 
			return;
		
		switch(stt) {
			case "Stamina":
				statPoints--;
				stamina++;
				break;
			case "Strength":
				statPoints--;
				strength++;
				break;
			case "Agility":
				statPoints--;
				agility++;
				break;
			case "Dexterity":
				statPoints--;
				dexterity++;
				break;
			case "Wisdom":
				statPoints--;
				wisdom++;
				break;
		}
	}
}

and here’s my healthManager

using UnityEngine;
using System.Collections;

public class HealthHandler : MonoBehaviour {
	public int maxHealth = 100;
	public int currentHealth = 100;
	public int stamina;
	public float healthBarLength;
	// Use this for initialization
	
	void Start () {
		healthBarLength = Screen.width / 2;
		// TRYING TO SET STAMINA = STATHANDLER.STAMINA
	}
	
	// Update is called once per frame
	void Update () {
	// AdjustCurrentHealth (0);
	}
	
	void OnGUI() {
		  GUI.Box(new Rect(10, 20, healthBarLength, 20), currentHealth.ToString() + "/" + maxHealth.ToString());
	}
	
	 public void AdjustCurrentHealth(int adj)  {
        currentHealth += adj;
        if(currentHealth <= 0) {
            currentHealth = 0;
        } else if(currentHealth > maxHealth) {
            currentHealth = maxHealth;
        }
        healthBarLength = (Screen.width / 2.0f) * ((float) currentHealth / maxHealth);
    }
}

It’s in a comment where I’m trying to set stamina to the statValue in StatHandler, I’ve tried so many way I don’t know what to do, I’ve had some help but I’m posting this for everyone because I’m going to sleep, whoever helps me get this fixed I may make a “Donation” to, or buy them some beer.

I guess your issue is

// TRYING TO SET STAMINA = STATHANDLER.STAMINA

so in the healthManager script add:

StatHandler statHnadler;

void Start(){
   statHandler = GetComponent<StatHandler>();
}

void Update(){
   stamina = statHandler.stamina;
}

Now in the top part, if you already have the components, you do not need to add them again. Just get them. But, I understand you may want to have a top class that managed the transactions between other classes but in this case, getting health and stat in order to pass stat to health is slower than getting stat in health directly.

It would appear that you should just be able to do:

stamina = GetComponent<StatHandler>().stamina; //TRYING TO SET STAMINE = STATHANDLER.STAMINA

You should not create a script called Component as it will lead to all sorts of confusion later, Component is the base class of many things like MonoBehaviour and Animation etc.

You probably should read one of the GetComponent tutorials on Unity Gems or read the brief description in the Gothcas article - these should help you work out what to call GetComponent on!