#TextMeshPro Input Fields Calculation / Result

1 messages ยท Page 1 of 1 (latest)

manic fossil
#

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

gloomy locust
#

sure thing, but should I use textmeshpro? I use the legacy one

manic fossil
#

i mean honestly yes

#

the old legacy is pretty bad

gloomy locust
#

oki, gonna use that

manic fossil
#

top Result is TMPro

#

bottom is legacy

#

๐Ÿคฎ

#

lol

gloomy locust
#

๐Ÿ’€๐Ÿ’€๐Ÿ’€

manic fossil
#

do u know how to use tmpro?

gloomy locust
#

first time

#

first day doing this calculator thing ๐Ÿคก

manic fossil
#

its pretty much the same... but u need to create font atlas' or a new material for each font u use

gloomy locust
#

oh cool, didn't know it was that easy

manic fossil
#

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

gloomy locust
#

will do

manic fossil
#

goood luck ๐Ÿ€

gloomy locust
#

thanks, I appreciate your time UnityChanwowUnityChanThumbsUp

manic fossil
#

hover over them

#

they should tell u why they're underlined

#

yellow isnt error.. its warning

gloomy locust
manic fossil
#

more like suggestions/optimizations

#

ahh yea its just saying u haven't used it yet

#

no problems at all

gloomy locust
#

ah oki

manic fossil
#

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

gloomy locust
#

but the underlined word, what should it based on? or how should I use it?

#

ah wait nvm I was lost lol

manic fossil
#

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..

manic fossil
#
  • 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 Result text 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.");
    }
}

}```

gloomy locust
manic fossil
#

"Ultra Twig" ๐Ÿชต lol

#

made it a "simple adder"

gloomy locust
#

I be trying to create random stuff so I can recycle stuff in the future lol

manic fossil
#

TextMeshPro Input Fields Calculation / Result

#

changed the name of the thread so others may find it useful

gloomy locust
#

๐Ÿ‘€๐Ÿ‘Œ๐Ÿ‘Œ

manic fossil
#

always be thinking about how u could re-use something

#

one of a programmer's top secrets

gloomy locust
#

yissss

manic fossil
#

anyway best of luck w/ what-ever your doing

#

see around the server ๐Ÿ‘‹ ๐Ÿ€