I am trying to create a program to display temperature converted between Celsius and Fahrenheit but im having some trouble. How can i have my Celsius Float = the number put into the input field.
Everything i have tried has resulted in an error telling me it cannot be directly converted the ways i have tried. Thank you.
The setup:
Empty GameObject with script(donut) attached. input field attached through inspector to script on gameobject. button even associated with the gameobject and script and the method CalcCelsius, pretty simple and it tries to parse out the float, if not it will hit the else in the if statement.
public class donut : MonoBehaviour {
public InputField inputField;
private float celsius = 0.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void CalcCelsius()
{
float temp = 0.0f;
if (float.TryParse (inputField.text, out temp))
{
Debug.Log ("Float was parsable to a float, gunna do some stuff to it");
}
else
{
Debug.Log ("unable to parse the value: " + inputField.text + " as a float, please check your input");
}
}
}