#TextMeshPro Input Fields Calculation / Result
1 messages ยท Page 1 of 1 (latest)
Ayo!
Got it figured out I think.. If u need help let me know i'll be happy to share how I did it..
i think thats how BMI works
Its probably better to do it as Digi was mentioning via the method in the inspector
i simply just referenced all the fields
sure thing, but should I use textmeshpro? I use the legacy one
oki, gonna use that
๐๐๐
do u know how to use tmpro?
well heres a little crash course
its pretty much the same... but u need to create font atlas' or a new material for each font u use
oh cool, didn't know it was that easy
and in scripting its
using TMPro; at the top for the using statement..
and then
^ i usually have to guess which ones to use.. but i know TMP_Text works most of the time..
when it doesn't i'll just try TextMeshProUGUI
will do
goood luck ๐
thanks, I appreciate your time 

am I doing something wrong?
hover over them
they should tell u why they're underlined
yellow isnt error.. its warning
more like suggestions/optimizations
ahh yea its just saying u haven't used it yet
no problems at all
ah oki
when u use it further into ur script that underline should disappear
by the way.. i was just showing examples.. u dont need all three of those types
probably just 2 TMP_InputFields for ur weight and height fields
and then a normal TMP_Text to display it.. or not even that if u just want to debug it
but the underlined word, what should it based on? or how should I use it?
ah wait nvm I was lost lol
thats the name of ur variable.. u can name it however u like
it goes protectionLevel Type name = value;
public Rigidbody myRigidbody;
private float myFloat;
etc..
you can do it many ways.. but here's how I did it w/ a button..
- The script has a reference to the weight input field.
- has reference to the height input field
- has a reference to a regular tmp text (for the result)
- and a public method called
PerformCalculation()
on the button I made (called Calculate) we reference the script and select the public method..
- fill in both fields and press the button..
- then the script takes those two values, parses to float (if it can).. does the math and outputs it in the
Resulttext mesh pro element
๐ Something similar to this: ```cs
using UnityEngine;
using TMPro;
public class TextInputTest : MonoBehaviour
{
[SerializeField] TMP_InputField weight_InputField;
[SerializeField] TMP_InputField height_InputField;
[SerializeField] TMP_Text resultText;
public void PerformCalculation()
{
if(float.TryParse(weight_InputField.text,out float playerWeight) &&
float.TryParse(height_InputField.text,out float playerHeight) &&
playerHeight > 0)
{
float bmi = playerWeight / (playerHeight * playerHeight);
resultText.text = bmi.ToString("00.00");
}
else
{
Debug.Log("Invalid input. Please enter valid weight and height.");
}
}
}```
@manic fossil Thank you very much! it works!
glad to hear ๐
"Ultra Twig" ๐ชต lol
i kept mine as a prefab.. never know when it'll come in handy
made it a "simple adder"
TextMeshPro Input Fields Calculation / Result
changed the name of the thread so others may find it useful
๐๐๐
thats the best thing to do..
always be thinking about how u could re-use something
one of a programmer's top secrets
yissss

