how to add a minimum to input fields.

so I’m making my first multiplayer game and trying to figure out the input field but this has stumped me.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class ButtonOff : MonoBehaviour
{

public Button Create;
public Button Join;

public TMP_InputField createInput;
public TMP_InputField joinInput;

// Start is called before the first frame update
void Start()
{

}
// Update is called once per frame
void Update()
{

}

}

u mean like
if(int.Parse(myInput.text) < min) myInput.text = min;

Okay, let’s try starting from a slightly different point here.

Since you are using InputFields and Buttons, you’ll want to set the function called either by “OnValueChanged” or “OnEndEdit” (I think those names are about right? Going from memory on that one) in the InputField.

When either of those functions passes its string value along to that function (i.e. with a string argument), you can then check its value and filter it as necessary.

public void FilterMinValue(string stringValue)
{
	// Use TryParse since it won't throw an exception
	// when the value isn't a valid integer
	// (in this example, "createValue" is related to whatever
	// you intend to do with this value)
	if(!int.TryParse(stringValue, out createValue))
	{
		createButton.interactable = false;
		createValue = min - 1; // Force the value to be invalid
		return;
	}
	createButton.interactable = (createValue >= min && createValue <= max);
}

can you tell me if this right or wrong:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class MIn : MonoBehaviour
{

public float min;
public float max;

public TMP_InputField createInput;
public Button Create;

// Start is called before the first frame update
void Start()
{
    
}

// Update is called once per frame
void Update()
{

}

public void FilterMinValue(string stringValue)
{
    // Use TryParse since it won't throw an exception
    // when the value isn't a valid integer
    // (in this example, "createValue" is related to whatever
    // you intend to do with this value)
    if (!float.TryParse(string, out float))
    {
        Create.interactable = false;
        createInput = min - 1; // Force the value to be invalid
        return;
    }
    Create.interactable = (createInput >= min && createInput <= max);
}

}