Hi,
I’m pretty new to unity and scripting in general, the problem I’m currently facing is having a class automatically calculate a variables value for me.
class Weapon_Info {
var Fire_Rate : float; //Time between shots (in seconds)
var DPS : float; //Damage per second
var Damage : float = (DPS * Fire_Rate;) // <- This is where I'm not sure
}
class Weapons {
var Basic : Weapon_Info;
var Canon : Weapon_Info;
}
var weapon : Weapons;
function Start(){
print(weapon.Basic.Fire_Rate);
print(weapon.Basic.DPS);
print(weapon.Basic.Damage);
}
A sample of my current code.
What it looks like in my editor
At the moment function Start() will print out:
0.5
10
0 //this should equal (10 * 0.5 = 5)
So its not calculating the Damage correctly.
What would be the best way for me to accomplish the automatic calculation of ‘Damage’, if it could somehow update on the fly inside the editor that would be even better.
Thanks in advance.