using UnityEngine; using UnityEngine.UI;
public class slide : MonoBehaviour {
Text text;
public Slider slider;
void Start(){
text = GetComponent<Text> ();
}
public void textscale(int value){
slider.value = text.fontSize;
}
}
Replace your current script with the following one:
public class slide : MonoBehaviour { public Text text; // Drag & drop the Text component inside the Inspector public void ChangeFontSize(float value) { ChangeFontSize( Mathf.RoundToInt( value ) ) ; } public void ChangeFontSize(int value) { text.fontSize = value; } }
Click on your Slider, add a new entry in the OnValueChanged
event.
slide > ChangeFontSize (Dynamic float)
Add script:
using UnityEngine; using UnityEngine.UI; public class ScalerScript : MonoBehaviour { public Text text; public void TextScale(Slider slider) { text.fontSize = (int)slider.value; } }
Create empty GameObject. Attach ScalerScript
to it and drag and drop your Text object to Text field of the script in the Inspector window:
Set up Slider. Drag and drop empty GameObject with ScalerScript attached to OnValueChanged
slider function. Drag and drop Slider element as a parameter to TextScale method. Set Slider's MaxValue
to 200:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.