Make a float variable change when another variable changes?
Hello,
I am trying to change a float variable value when another variable changes like so:
public float minsMP1 = 0;
public float expMP1 = minsMP1 * 0.01;
where minsMP1 is changed upon a button click... The method of changing minsMP1 is OK, i got it but I cannot change the value of expMP1 when minsMP1 changes and it gives me the 'error CS0236: a field initializer cannot reference the nonstatic field,method or property 'GameTime.minsMP1'.
Any ideas are appreciated :)
how is $$anonymous$$s$$anonymous$$P1 changed by that Button?
//Add $$anonymous$$inute on $$anonymous$$P1 public void add$$anonymous$$inute$$anonymous$$P1 () { if ($$anonymous$$s$$anonymous$$P1 < 10) { $$anonymous$$s$$anonymous$$P1 += 1; } else { $$anonymous$$s$$anonymous$$P1 += 10; } }
so why don't you Change it into: public void add$$anonymous$$inute$$anonymous$$P1 () { if ($$anonymous$$s$$anonymous$$P1 < 10) { $$anonymous$$s$$anonymous$$P1 += 1; } else { $$anonymous$$s$$anonymous$$P1 += 10; } exp$$anonymous$$P1=$$anonymous$$s$$anonymous$$P1*0.01f; }
Answer by Caruzo · Nov 02, 2015 at 05:59 PM
public float minsMP1 = 0;
public float expMP1;
public void Update () {
expMP1 = minsMP1 * 0.01;
}