How do i store a InputField's input in a float?

I’m trying to make kind of a practise program. And i want 2 random numbers to be multiplied by eachother, I want the user to choose the minimal and maximal number of the two numbers. So something like this: UnityEngine.Random.Range(Min, Max); But the min and max have to be floats. How do I store the InputField in a Float/Var and/or convert it to a float? Pls help me with an example script. Btw. I’m just a beginner trying to understand c#.

Hi,

1: you want to reference your input fields and result text field, I assume you want to use Unity UI.

2: you want to add method that will be called by the UIButton.

3: you can use float.Parse() to convert a string to a float value.

4: set your InputField validation to Decimal numbers.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class RandomValues : MonoBehaviour
{
	public InputField fieldMin;
	public InputField fieldMax;
	public Text textResult;

	public void GenerateRandomValue ()
	{
		float min = float.Parse(fieldMin.text);
		float max = float.Parse(fieldMax.text);

		textResult.text = Random.Range(min, max).ToString();
	}
}

Hey this Works totally fine! But I want the textResult.Text to be an Int. So instead of 1.5433667 → 2

Thanks Btw!!!