I am having trouble keeping a variable between 2 scripts the same. I have one deriving from the other, yet one of the variables is treated as a different int.
First one
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Warmth : MonoBehaviour
//Warmth Script, first one
{
public int heatLvl; // = 100f;
public string sceneName;
void Start()
{
InvokeRepeating("decreaseHeat", .25f, .25f);
}
void decreaseHeat()
{
if (heatLvl > 0)
{
heatLvl -= 1;
}
}
void FixedUpdate()
{
Debug.Log(heatLvl);
if (heatLvl <= 0)
{
SceneManager.LoadScene(sceneName);
}
}
private void OnTriggerEnter2D(Collider2D other)
{
heatLvl = 100;
}
}
second one
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Health : Warmth {
//Health script, second one
private const float MAX_HEALTH = 100f;
public Warmth warmth;
public float health = MAX_HEALTH;
private Image healthBar;
private void Start()
{
healthBar = GetComponent<Image>();
InvokeRepeating("decreaseHeat", .25f, .25f);
}
private void FixedUpdate()
{
healthBar.fillAmount = health / MAX_HEALTH;
health = heatLvl;
}
}