Hello, first off sorry for asking so many questions lately. Now on with my question. My variables are changing far less than they should. Some change by one per 5 seconds, some by 0. Here is my code.
var population = 100;
var food = 100.0;
var happiness = 60.0;
var farms = 5;
var harvest = farms * 5;
var hunger = population * 0.25;
var starvation = 0.0;
InvokeRepeating ("FoodCycle", 0, 5);
function FoodCycle () {
var populationgrowth = Random.Range(population / 10, population / 100);
population += populationgrowth * Time.deltaTime;
food += harvest * Time.deltaTime;
food -= hunger * Time.deltaTime;
if (food < population / 10)
happiness -= 1 * Time.deltaTime;
if (food < 1)
happiness -= 5 * Time.deltaTime;
if (1 > food)
starvation += 1 * Time.deltaTime;
if (1 < starvation)
population -= 1;
if (1 < starvation)
starvation -= 1;
}
EDIT:
Now that my variables are updating at the right time there is another problem. My variables that depend on each other don't update in relation to each other. For example as population increases hunger does not. Here's my current code:
var population = 100.0;
var food = 100.0;
var happiness = 60.0;
var farms = 5.0;
var harvest = farms * 5.0;
var hunger = population * 0.25;
var starvation = 0.0;
InvokeRepeating ("FoodCycle", 0.0, 120.0);
var populationgrowth = Random.Range(population / 100.0, population / 50.0);
function FoodCycle () {
population += populationgrowth;
food += harvest;
food -= hunger;
if (food < population / 10.0)
happiness -= 5.0;
if (food < 1.0)
happiness -= 10.0;
if (1 > food)
starvation += 1.0;
if (1 < starvation)
population -= 1.0;
if (1 < starvation)
starvation -= 1.0;
if (food < 0.0)
food = 0.0;
if (population < 0.0)
population = 0.0;
if (food < population)
populationgrowth = 0.0;
if (food > population * 2)
happiness += 1.0;
if (happiness > 100)
happiness = 100;
if (happiness < -100)
happiness = -100;
}