Troble with strings to ints

Hi im trying to convert a string into an int and adding an if condition but the condition seems to not trip no matter what i type, thanks.

using UnityEngine;
using TMPro;
using UnityEngine.UIElements;

public class Evasion : MonoBehaviour
{
    public TextMeshProUGUI text;
    public GameObject[] dormant;
    public GameObject[] activated;
    public TextMeshProUGUI error;
    TextMeshProUGUI the;
    void Start()
    {
        the = error.GetComponent<TextMeshProUGUI>();
        foreach (GameObject gameObject in dormant)
        {
            gameObject.SetActive(true);
        }
    }
    // Update is called once per frame
    void Update()
    {

    }
    public void Calculation()
    {

        int value = System.Convert.ToInt32(text);
        if (value<=0 || value>=101)
        {
            the.text="Please input a valid number";
        }
        else
        {
            foreach(GameObject gameObject in dormant)
            {
                gameObject.SetActive(false);
            }
            foreach (GameObject gameObject in activated)
            {
                gameObject.SetActive(true);
            }
        }
    }
}

1 Answer

1

Your trying to convert ‘text’ to an int, but ‘text’ is some TextMeshProUGUI GUI.
Maybe you meant to retrieve the string from a component or class?

Possibly "text.text" to get the string out of the TextMeshPro object.

Oh, i didn´t know the difference, thanks