Jump to content

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

CreepyPL
Go to solution Solved by minibois,
// Converting a string to int:
int.TryParse(myString, out myInt);

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

 

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 comment
Share on other sites

Link to post
Share on other sites

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

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

 

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

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

×