I am trying to define an integer “maxHealth” in one script and access its value in another. I don’t understand what I’m doing wrong. Here are my scripts.
public class AttributeSys1 : MonoBehaviour
{
#region define variables
//sets all stat integers
public int strengthLevel;
public int speedLevel;
public int intelligenceLevel;
public int willpowerLevel;
public int defenseLevel;
public int maxHealthLevel;
public int maxEnergyLevel;
public int strength;
public int speed;
public int intelligence;
public int willpower;
public int defense;
public int maxHealth;
public int maxEnergy;
#endregion
#region Start Function
// Use this for initialization
void Start ()
{
//set default stat values
strengthLevel = 0;
speedLevel = 0;
intelligenceLevel = 0;
willpowerLevel = 0;
defenseLevel = 0;
maxEnergyLevel = 0;
maxHealthLevel = 0;
}
#endregion
#region SetStats
public void SetStats()
{
strength = ((strengthLevel * 5) + 20);
speed = ((speedLevel * 5) + 20);
intelligence = ((intelligenceLevel * 5) + 20);
willpower = ((willpowerLevel * 5) + 20);
defense = ((defenseLevel * 5) + 20);
maxEnergy = ((maxEnergyLevel * 10) + 100);
maxHealth = ((maxHealthLevel * 10) + 100);
}
#endregion
// Update is called once per frame
void Update ()
{
SetStats();
}
using UnityEngine;
using System.Collections;
public class Vitals : MonoBehaviour {
public int curHealth;
public int maxHealth1;
public int curEnergy;
public int maxEnergy1;
// Use this for initialization
void Start ()
{
maxHealth1 = GetComponent<AttributeSys1>().maxHealth;
curHealth = maxHealth1;
maxEnergy1 = GetComponent<AttributeSys1>().maxEnergy;
curEnergy = maxEnergy1;
}
// Update is called once per frame
void Update () {
}
}