Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
CreepyPL

C#/Unity how to convert TextMeshProUGUI.text to int

// Converting a string to int:
int.TryParse(myString, out myInt);

// Converting an int to String:
string newString = myInt.ToString();

 

Recommended Posts

Posted · Original PosterOP

The title basically says it.
Heres the code:
 

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

public class LevelLoader : MonoBehaviour
{
    [SerializeField] int amountOfScenesBeforeLevels;
    [SerializeField] TextMeshProUGUI levelNumber;

    public void LoadNextLevel()
    {
        SceneManager.LoadScene(amountOfScenesBeforeLevels + levelNumber.text);
        Debug.Log(levelNumber.text);
        Debug.Log(amountOfScenesBeforeLevels);
    }
}

image.png.524cbe28201ccf05fc927bea1d452d37.pngimage.png.b2767a3d2dcae85b19e5dc3f2ccfebdb.png

image.png

Link to post
Share on other sites
Posted · Best Answer
// Converting a string to int:
int.TryParse(myString, out myInt);

// Converting an int to String:
string newString = myInt.ToString();

 


"There's no such thing as perfect. You're beautiful as you are Courage. With all your imperfections you can do anything." - Bathtub Barracuda

"How can someone win if winning means that someone loses" - Scatman John

"64 bits, 32 bits, 16 bits, 8 bits, 4 bits, 2 BITS, 1 BIT, HALF BIT, QUARTER BIT, THE WRIST GAAAAAAME!!!" - Angry Video Game Nerd

Gear:                           .                                                                                                                         .

Spoiler

PC:

CPU: AMD Ryzen 7 1700 || Motherboard: MSI X370 Gaming Pro Carbon || RAM: 2x8GB G.Skill TridentZ RGB 3200Mhz (running at 2933Mhz) || GPU: Gigabyte Auros RX 580 4GB || Storage: Samsung 960 EVO 250GB + Seagate Barracuda 2TB || Cooling: Be Quiet! Dark Rock 3 || Case: Thermaltake Core G21 TG || PSU: Corsair RMx 750W

Peripherals:

Headphones: Beyerdynamic DT-990 250 Ohm || Mouse: Roccat Kiro || Keyboard: Coolermaster Masterkeys Pro S RGB || Mousepad: CM Storm Swift-RX XXL || Graphics tablet: Wacom Intuos Pen Small

Old PC:

CPU: AMD Athlon X2 255 || Motherboard: ASUS M4A89GTD PRO || RAM: 4x2GB DDR3 || GPU: Nvidia Quadro 512MB || Case: Antec Sonata III || PSU: Antec Earthwatts 500W Bronze

Minibois' Digital Art Thread

Reviews: Coolermaster Masterkeys Pro S RGB || Wacom Intuos Pen Small || Roccat Kiro

Threads: Pokémon Thread || Dutch Talk || Super Smash Bros. Melee Thread

Setup: Current setup

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×