I’m making a game that’s about trade, game has 9 different city to trade. I want player to buy a good from a cheaper price and sell it to another city.
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using TMPro;
using UnityEngine;
using UnityEngine.PlayerLoop;
using UnityEngine.UI;
public class WeaponryPrices : MonoBehaviour
{
public int buyprice0;
public int sellprice0;
public float countdown;
public Text text0;
public Text selling_text0;
private void Start()
{
UpdateText(text0, buyprice0);
UpdatesellText(selling_text0, sellprice0);
}
void UpdateText(Text tex,int value)
{
tex.text = "Buy " + value;
}
void UpdatesellText(Text tex, int value)
{
tex.text = "Sell " + value;
}
private void Update()
{
countdown += Time.deltaTime;
if(countdown > 10f)
{
buyprice0 = Random.Range(30,60);
sellprice0 = buyprice0 - 5;
UpdateText(text0, buyprice0);
UpdatesellText(selling_text0, sellprice0);
countdown -= 10f;
}
}
}
When I enter the shop it shows me in the button’s text “button”, after 10 seconds it changes so I noticed that Update() method doesn’t work when player isn’t in the scene.
How can I fix that problem? I want to change prices when the player is in the map.