- Home /
I'm trying to sort my Npc's into different social classes
I'm trying to put my NPCs into social classes by creating a function to calculate their income and then use the array to put them into the class. My idea was to use the Mathf.Clamp inside an if statement to basically say "if my gross is between 0 - 5000" then they fall into the "poor" class
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Class_System : MonoBehaviour
{
//public float income;
//public string job;
//Income variables
//public int grossIncome;
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);
}
}
Also I commented out a lot of the variables I have yet to use sorry if it confuses you.
Answer by tanoshimi · Sep 06, 2014 at 07:23 AM
Not sure why you're using Clamp - you just need the if:
if (myGross < 4999) {
//NPC is poor
}
else if (myGross < 9999) {
//NPC is middle-class
}
else {
// NPC is elite
}
so by using this I would access the array like this
if (myGross < 4999) {
finClassArray[0]
//NPC is poor
}
else if (myGross < 9999) {
//NPC is middle-class
}
else {
// NPC is elite
}
Would that (line 2) be how I access the array once I have my conditions set.
I managed to make it work thank you, I'm surprised the condition for the if statement was that simple. Thank you !
Your answer
Follow this Question
Related Questions
if statement only ever triggering the first condition even if it's false and the second one is true 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Neater way to test an Enum in a different script? 1 Answer
I'm having trouble setting a bool. 2 Answers
How do I combine two arrays of a common parent class? 1 Answer