0

the first random is stays the same for example its 50 the child class text will be 50 and after another random for example is 45 it should be 50 + 45 not replace the value with 45

Parent class

    public class BattleSystemScript : GameManagerRevamped
   {
      static public int CoinsRandom;
      public TextMeshProUGUI Coins;

         void Start()
         {  
           CoinsRandom = Random.Range(30, 50);
           Coins.text = CoinsRandom.ToString();
         } 
  }

Child class

public class PlayerValues : BattleSystemScript
{
  int CoinsRandomValue;
  public TextMeshProUGUI PlayerCoins;         
       void Start()
       {
        CoinsRandomValue += CoinsRandom;
        PlayerCoins.text = CoinsRandomValue.ToString();
       }
}

2 Answers2

1

Make the parent Start a virtual method

public class BattleSystemScript : GameManagerRevamped
{
    static public int CoinsRandom;
    public TextMeshProUGUI Coins;

    protected virtual void Start()
    {  
        CoinsRandom = Random.Range(30, 50);
        Coins.text = CoinsRandom.ToString();
    } 
}

And override it in the child class in order to extend it

public class PlayerValues : BattleSystemScript
{
    int CoinsRandomValue;
    public TextMeshProUGUI PlayerCoins;         
    protected override void Start()
    {
        // call to the parent Start
        base.Start();

        CoinsRandomValue += CoinsRandom;
        PlayerCoins.text = CoinsRandomValue.ToString();
    }
}
derHugo
  • 83,094
  • 9
  • 75
  • 115
0

So I just had to make the child class static too lol

--->

static public int CoinsRandomValue;
static public int DiamondsValues;
static public int ExperienceRandomValue;