Question by
josesesi · Nov 22, 2020 at 05:04 PM ·
programmingstats
What is the most effective way of increasing one of three different stats from a player from a single script? or should I do it in a different way?
Hi, I'm making a game where the player has three different stats which can be increased by different spots I call trainers (You go to the gym to increase your strength for example).
However I want this to be done by a single script shared by all trainers but I don't know how to increase a specific stat while still having reference to the others. public void Train() { if (playerStats.money >= Price) { //Here I need to check what stat is being increased by this specific trainer } else { Debug.Log("You don't have enough money"); } }
I could just slap booleans and a bunch of ifs and be done with it but it feels like it's a bad way of doing it (This is what it would look like)
public void Train()
{
if (playerStats.money >= Price)
{
if(StrengthTrainer)
{
//Increase Strength
//Pass Time
//Drain Energy
}
if (AgilityTrainer)
{
//Increase Agility
//Pass Time
//Drain Energy
}
if (Whatever)
{
//Increase Whatever
//Pass Time
//Drain Energy
}
}
}
Thanks in advance!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613020321im_/https://answers.unity.com/themes/thub/images/avi.jpg)