I am trying to create a system that will generate a class that is driven by internal logic and I need some suggestions on best practices.
Lets say I have class of person, with the following properties:
- Hat
- smoker
- glasses
- Bald
- eatIceCream
- sadness
Let say I have a 50 percent chance of the player wearing a hat if their bald, and a 20 percent chance to wear glasses if they smoke. And if they don’t smoke they don’t eat ice cream, and if they don’t eat icecream their sadness goes up by 20.
What’s the best way to create a function to handle this logic that depends on one another? I am not a current fan of the way I am doing it now with the if statements (Or switch) because this is a lot of code that I find messy.
Has anyone dealt with this before? Or have a paper I can read of dependent logic practices?
public class Player
{
bool hat;
bool bald;
bool smoker;
bool glasses;
bool eatIceCream;
int sadness;
void Start()
{
if(bald){
hat = if(Random.Range(0,100) >= 50);
//All the other logic.
}
}
}