how to do simple calculations with InputField ?

Updated on July 28, 2018 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on July 28, 2018

I use following script but nothing happens

public InputField BasePrice; //assign base price input field here
 public InputField SellingPrice; //assign selling price input field here
 public Text Profit; //assign profit text here
 void cal()
 {
 int BP = Convert.ToInt32(BasePrice.text); // convert it into integer
 int SP = Convert.ToInt32(SellingPrice.text); // convert it into integer
 int P = SP-BP; // do the calculation, find the result
 Profit.text = P.ToString(); //turn result back into string and display it in the profit text
}

 

it looks like it should work but it doesnt. after I enter value in SP & BP and hit enter, nothing happenes. please help. thanks in advance. 

  • Liked by
Reply