Hey, I’m trying to get a value per each item within a list (with multiple properties). ‘e.hours’ should each, individually per item in the list, be multiplied by ‘GetHourlyRate’. When I format it like I think it should be done, as in the last example, it is only writing the total for the last field instead of for each of them.
I can pretty much confirm that the GetHourlyRate function is working fine, as well as the ‘hours’ property, so that shouldn’t be an issue. I’ve played around with the debug location with no luck. I’ll eventually get the results out of the function, otherwise I’d be fine with one of the other ways. But for asking the question I wanted to keep the issue isolated to why I can’t get a variable assigned to the individual totals (I can hopefully take it from after that point) and I’m just wondering what is out of place or what step I am missing.
Thanks!
public float CalculatePayEach()
{//This Works.
foreach (Employees e in fields)
Debug.Log(e.hours * GetHourlyRate());
}
return payEach;
public float CalculatePayEach()
{//And this works.
float x =1;
foreach (Employees e in fields)
Debug.Log(x * e.hours * GetHourlyRate());
// myListChild.transform.position = Vector3.one
}
return payEach;
public float CalculatePayEach()
{//This only prints one, the last, item.
float x = 1;
foreach (Employees e in fields)
x = e.hours * GetHourlyRate();
Debug.Log(x);
}
return payeach;