I'm trying to get user's height from the input and do if-else statement, then display the size of clothes they should get according to their height. I have no idea how to convert string to a number.
Here's my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour
{
public string number;
public GameObject inputField;
public GameObject textDisplay;
public void ShowSize() {
number = inputField.GetComponent<Text>().text;
if (number <= 167) {
textDisplay.GetComponent<Text>().text = "You are suitable to get S size.";
}
else if (number >= 168 && number <= 177) {
textDisplay.GetComponent<Text>().text = "You are suitable to get M size.";
}
else if (number >= 178 && number <= 184) {
textDisplay.GetComponent<Text>().text = "You are suitable to get L size.";
}
else if (number >= 185) {
textDisplay.GetComponent<Text>().text = "You are suitable to get XL size.";
}
else {
textDisplay.GetComponent<Text>().text = "Please enter a correct height!";
}
}
}
Any help would be appreciated, thank you!