Im trying to make a game where one aspect is my citizens (NPCs) will be taxed as a source of income for the city , the way I decided to go about it was to create a function that calculates their gross income and then use this to number to put them into a certain “class” I.e. poor, and middle. I used a Array containing the different classes
To sum up my question, Whats the best way to go about this, using list, enum, array, or dictionaries? How do you make an if statement based on a number being in a certain range?
Here’s the code I commented out a lot of the unused variables:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Class_System : MonoBehaviour
{
//public float income;
//public string job;
string[] finClassArray = {"Poor", "Middle Class", "Elite"};
public int myHourly;
private int myMonthly;
public int myGross;
void Start ()
{
_monthlyIncome ();
_grossIncome();
if ((Mathf.Clamp (myGross, 0, 4999)) {
Debug.Log ("We made it");
}
}
void Update ()
{
}
public int _monthlyIncome() //calculate Monthly Income
{
myMonthly = myHourly * 31;
//myGross = myMonthly * 12;
Debug.Log(gameObject.name);
Debug.Log("Makes");
Debug.Log (myMonthly);
return myMonthly;
}
public int _grossIncome() //calculates Gross income
{
myGross = myMonthly * 12;
Debug.Log (myGross);
return(myGross);
}
}
I would have a class that manages the classes. ClassManager, then have it so you can pass in a value, in this case the income, and have it return an enum that represents the type of class they are.
public class ClassManager : System.Object {
public enum ClassType {
Poor,
MiddleClass,
UpperClass
}
public static ClassType GetClassType(int income) {
// if statement here
return ClassType;
}
}
Sorry, typed this on mobile. If you do a google search you can find the income ranges on how the government ranks households based on income. Hope this helps.
Well it depends on how you want to go about things. What will be the purpose? I know you said the taxation but for what reason? Depending on the answer will spark the most optimal way of doing things. (Singleton might be the way to go so far).
Well the game i’m trying to make is a gonna be like a village management simulator. The taxation will be one of the major sources of income for the village I’m managing along side trade and some other things.
sorry it took so long to reply, I hope that the answer you where looking for