- Home /
How to change text size in c# by user?
I have large text (using textmesh pro) and his textsize is 38. in my settings panel i have two buttons + and - for user to be able to change the text size. What i need to write in c# that this buttons will work. Thanks for your time.
Comment
Best Answer
Answer by FernandoHC · Sep 10, 2018 at 05:22 PM
This is one way to do it, just assign the text object to the script in the editor and set the value you want to add or subtract in the range variable. Then assign the methods ClickPlusButton and ClickMinusButton at the buttons you want to use.
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class TestScript : MonoBehaviour
{
public TextMeshProUGUI theText;
public float range = 1f;
public void ClickPlusButton()
{
theText.fontSize+=range;
}
public void ClickMinusButton()
{
theText.fontSize -= range;
}
}