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.