help with accessing info from a separate script c#

SO I haven’t figured it out… It works no errors, but a part of the script doesn’t work… The health bar increasing health per level doesn’t work. The endurance goes up every level however health is still displayed as the initial 100.

scripts:

using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour {

	public int curHealth;
	public GameObject player;

	public int maxHealth;
	public int endurance = 10;
	public int wisdom = 10;
	public int dexterity = 10;
	public int intelligence = 10;
	public float healthBarlength;
	

	public bool isDead = false;
	
	
	// Use this for initialization
	 void Start () 
	{
		curHealth = 100;
		maxHealth = endurance * 10;
	
	}
	
	// Update is called once per frame
	void Update () {
		
		AdjustCurrentHealth(0);
		
		if(curHealth < 1)
		{
			curHealth = 0;
			isDead = true;
			Destroy(player);
		}
		if(curHealth > maxHealth)
		{
			curHealth = maxHealth;
		}
	}
	
	public void AdjustCurrentHealth(int adjHealth)
	{
		curHealth += adjHealth;
		healthBarlength = (Screen.width / 2) * (curHealth / (float)maxHealth);
		
	}
	
	void OnGUI(){
		GUI.Box (new Rect(20,15,200,20), "HP:" + curHealth + "/" + maxHealth);			
				
	}
}

and

using UnityEngine;
using System.Collections;

public class PlayerLevel : MonoBehaviour {
	
	public int curLevel = 1;
	private int maxLevel = 60;
	
	public int curExp = 0;
	private int maxExp = 100;
	
	private bool LevelUp = false;

	// Use this for initialization
	void Start () {
				
//		PlayerHealth playerHealth = gameObject.GetComponent<PlayerHealth>();
//		PlayerMana playerMana = gameObject.GetComponent<PlayerMana>();
	
	}
	
	// Update is called once per frame
	void Update () {
		
		PlayerHealth playerHealth = gameObject.GetComponent<PlayerHealth>();
		PlayerMana playerMana = gameObject.GetComponent<PlayerMana>();
		
		AdjustCurrentExp(0);
		if (curExp >= maxExp) {
			curExp -= maxExp;
			curLevel ++;
			LevelUp = true;
			playerHealth.endurance += (1 * curLevel);
			playerHealth.intelligence += (1 * curLevel);
			
//			Change the following line for the Experience formula based on each level 
			maxExp += (35 * (curLevel * 3) * 2);
		}
	}
	void OnGUI(){
		GUI.Box (new Rect (20, 200, 200, 20), "EXP:" +curExp + "/" + maxExp);
		GUI.Box (new Rect(20, 55, 35, 20), " " + curLevel);
					}
	public void AdjustCurrentExp(int adjExp){
		curExp += adjExp;
	}
		
}

So the section for level up

		AdjustCurrentExp(0);
		if (curExp >= maxExp) {
			curExp -= maxExp;
			curLevel ++;
			LevelUp = true;
			playerHealth.endurance += (1 * curLevel);
			playerHealth.intelligence += (1 * curLevel);

this part works, I can see it in the editor it goes up like it should. However in the PlayerHealth it does not adjust the maxHealth

	// Use this for initialization
	 void Start () 
	{
		curHealth = 100;
		maxHealth = endurance * 10;
	
	}

this section is not working it just stays at 100 health.

any help would be appreciated.

Please help

Start only gets called at the beginning of an object’s life cycle (when the object is instantiated).
What you probably want to do is in your AdjustCurrentHealth method, add a line as you have in your Start method:

    public void AdjustCurrentHealth(int adjHealth)
    {
        curHealth += adjHealth;
        maxHealth = endurance * 10;
        healthBarlength = (Screen.width / 2) * (curHealth / (float)maxHealth);
    }

Since this method is called in the Update method which is called every frame, you can be sure that maxHealth is set properly based on endurance.

Thank you so very much, finally a functional level/health/mana system working :), you are a god send my friend.