Hi so I want to multiply two variables and set the outcome to another variable, however, I always get an error. Here’s my code
public class IntegersValues : MonoBehaviour
{
public float Multiplier = 0.02f;
public float BaseMulti = 100f;
public float Endmultiplier = Multiplier+BaseMulti;
}
public static float Multiplier = 0.02f;
public static float BaseMulti = 100f;
But I suggest you not to initialize a variable like that. Declare the variable and make the calculation inside a method like start() for example :
public float Endmultiplier;
public float Multiplier = 0.02f;
public float BaseMulti = 100f;
void Start()
{
Endmultiplier = Multiplier + BaseMulti;
// this will show the value of Endmultiplier in the Console
Debug.Log(Endmultiplier);
}
Your code will work if you make Endmultiplier a property, you declare it like public float Endmultiplier {get(return Multiplier+BaseMulti;} } or just make a method to do it.