I have variable ‘capacity’ which is updating normally, but I can’t get an updated value in another class, but initial value is there. Help me :<
public class housingPanelScript : MonoBehaviour
{
public Housing houseObj;
public TextMeshProUGUI capacity_txt;
public int capacity = 10;
void Update()
{
capacity_txt.text = "max capacity: " + capacity.ToString();
}
// some code
public void upgradeHouse()
{
capacity += 10;
Debug.Log("capacity " + capacity);
}
}
// Score is updating btw (ontriggerenter2d method)
public class Spawn : MonoBehaviour
{
public GameObject man;
int spwCount = 0;
public housingPanelScript house;
public Destroyer score;
public void spawn()
{
if (score.i < house.capacity && spwCount < house.capacity)
{
Instantiate(man, new Vector2(-1, 1), Quaternion.identity);
spwCount++;
}
else
Debug.Log("not spwn " + house.capacity + " " + score.i);
}
}