how to Change Font Size of UI Text element using UI Slider in unity C#?
up vote
0
down vote
favorite
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;
}
}
c# visual-studio user-interface unity3d text
add a comment |
up vote
0
down vote
favorite
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;
}
}
c# visual-studio user-interface unity3d text
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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;
}
}
c# visual-studio user-interface unity3d text
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;
}
}
c# visual-studio user-interface unity3d text
c# visual-studio user-interface unity3d text
asked Nov 9 at 7:44
Nouman Khan
156
156
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
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.- Drag & drop the gameObject holding the script, and select
slide > ChangeFontSize (Dynamic float)
add a comment |
up vote
1
down vote
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
Vertical Overflow
toOverflow
for your Text element:
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'sMaxValue
to 200:
- Run the scene.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
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.- Drag & drop the gameObject holding the script, and select
slide > ChangeFontSize (Dynamic float)
add a comment |
up vote
1
down vote
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.- Drag & drop the gameObject holding the script, and select
slide > ChangeFontSize (Dynamic float)
add a comment |
up vote
1
down vote
up vote
1
down vote
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.- Drag & drop the gameObject holding the script, and select
slide > ChangeFontSize (Dynamic float)
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.- Drag & drop the gameObject holding the script, and select
slide > ChangeFontSize (Dynamic float)
answered Nov 9 at 9:13
Hellium
4,7931837
4,7931837
add a comment |
add a comment |
up vote
1
down vote
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
Vertical Overflow
toOverflow
for your Text element:
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'sMaxValue
to 200:
- Run the scene.
add a comment |
up vote
1
down vote
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
Vertical Overflow
toOverflow
for your Text element:
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'sMaxValue
to 200:
- Run the scene.
add a comment |
up vote
1
down vote
up vote
1
down vote
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
Vertical Overflow
toOverflow
for your Text element:
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'sMaxValue
to 200:
- Run the scene.
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
Vertical Overflow
toOverflow
for your Text element:
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'sMaxValue
to 200:
- Run the scene.
answered Nov 9 at 9:28
Andrew Kotov
346210
346210
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53221629%2fhow-to-change-font-size-of-ui-text-element-using-ui-slider-in-unity-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown