scripting text for TextMeshPro in Unity

Found a good post about it:
https://forum.unity.com/threads/changing-textmeshpro-text-from-ui-via-script.462250/

pretty simple really, just make sure to use:
using TMPro;
TextMeshProUGUI (instead of just TextMeshPro)

//

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


public class KarmaPlayer : MonoBehaviour
{


public int karma;
public int startingKarma=100;
public int maxKarma;


TextMeshProUGUI textbox;


// Start is called before the first frame update
void Start()
{
karma = startingKarma;
textbox = GetComponent<TextMeshProUGUI>();


printKarma();
}


// Update is called once per frame
void Update()
{

}


void printKarma()
{
textbox.text = "Karma" + karma.ToString();
}




}


Comments

Popular posts from this blog

guy

magenta girl

IQ range and occupation