What I want to do here is change the MaxHealth Value each time the “Vitality Stat” Value changes. For example
Maxhealth = 100 + (Vitality * 8); (This would give me an error message because I would do this.
PlayerStats playerStats;
public float MaxHealth = 100 + (playerStats.Vitality * 8);
public void Start{
ETC....
}
This would give me a weird error message.
Then I tried to do.
public float maxHealth;
void Start ()
{
maxHealth = (100 + (playerStats.Vitatlity * 8) / 2);
currentHealth = maxHealth;
currentMana = maxMana;
}
This wouldnt Work either… And i also tried it in in the Update method which seemed more correct but still it didnt do what i wanted it to doo!
Here are my 2 scripts that are needed for this to hopefully work.
public class PlayerHealth : MonoBehaviour {
PlayerStats playerStats;
public float currentHealth;
public float maxHealth;
public Slider playerHealthBar;
public int healthRegen = 4;
public float currentMana;
public float maxMana = 1000;
public Slider playerManaBar;
public int manaRegen = 12;
CharacterController playerMovement;
private bool isDead;
void Start ()
{
currentHealth = maxHealth;
currentMana = maxMana;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Minus))
DealDamage(6);
if (Input.GetKeyDown(KeyCode.Period))
UseMana(52);
if (currentHealth < maxHealth)
currentHealth += healthRegen * Time.deltaTime;
if (currentMana < maxMana)
currentMana += manaRegen * Time.deltaTime;
if (currentHealth <= 0)
KillPlayer();
}
public void DealDamage(int damageValue)
{
currentHealth -= damageValue;
}
public void SetMaxHealth()
{
currentHealth = maxHealth;
}
void UseMana(float manaUseValue)
{
currentMana -= manaUseValue;
if (currentMana <= 0)
currentMana = 0;
}
void KillPlayer()
{
Destroy(gameObject);
}
}
public class PlayerStats : MonoBehaviour {
public float Strength = 6;
public float Vitatlity = 10;
public float Agility = 6;
public float Intellect = 6;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}