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;

}


}









share|improve this question


























    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;

    }


    }









    share|improve this question
























      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;

      }


      }









      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 7:44









      Nouman Khan

      156




      156
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote















          1. 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;
            }
            }


          2. Click on your Slider, add a new entry in the OnValueChanged event.


          3. Drag & drop the gameObject holding the script, and select slide > ChangeFontSize (Dynamic float)






          share|improve this answer




























            up vote
            1
            down vote















            1. Add script:



              using UnityEngine;
              using UnityEngine.UI;

              public class ScalerScript : MonoBehaviour
              {
              public Text text;

              public void TextScale(Slider slider)
              {
              text.fontSize = (int)slider.value;
              }
              }


            2. Create empty GameObject. Attach ScalerScript to it and drag and drop your Text object to Text field of the script in the Inspector window:



            enter image description here



            enter image description here




            1. Set Vertical Overflow to Overflow for your Text element:
              enter image description here


            2. 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:



            enter image description here




            1. Run the scene.






            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














               

              draft saved


              draft discarded


















              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

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote















              1. 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;
                }
                }


              2. Click on your Slider, add a new entry in the OnValueChanged event.


              3. Drag & drop the gameObject holding the script, and select slide > ChangeFontSize (Dynamic float)






              share|improve this answer

























                up vote
                1
                down vote















                1. 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;
                  }
                  }


                2. Click on your Slider, add a new entry in the OnValueChanged event.


                3. Drag & drop the gameObject holding the script, and select slide > ChangeFontSize (Dynamic float)






                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote











                  1. 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;
                    }
                    }


                  2. Click on your Slider, add a new entry in the OnValueChanged event.


                  3. Drag & drop the gameObject holding the script, and select slide > ChangeFontSize (Dynamic float)






                  share|improve this answer














                  1. 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;
                    }
                    }


                  2. Click on your Slider, add a new entry in the OnValueChanged event.


                  3. Drag & drop the gameObject holding the script, and select slide > ChangeFontSize (Dynamic float)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 9 at 9:13









                  Hellium

                  4,7931837




                  4,7931837
























                      up vote
                      1
                      down vote















                      1. Add script:



                        using UnityEngine;
                        using UnityEngine.UI;

                        public class ScalerScript : MonoBehaviour
                        {
                        public Text text;

                        public void TextScale(Slider slider)
                        {
                        text.fontSize = (int)slider.value;
                        }
                        }


                      2. Create empty GameObject. Attach ScalerScript to it and drag and drop your Text object to Text field of the script in the Inspector window:



                      enter image description here



                      enter image description here




                      1. Set Vertical Overflow to Overflow for your Text element:
                        enter image description here


                      2. 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:



                      enter image description here




                      1. Run the scene.






                      share|improve this answer

























                        up vote
                        1
                        down vote















                        1. Add script:



                          using UnityEngine;
                          using UnityEngine.UI;

                          public class ScalerScript : MonoBehaviour
                          {
                          public Text text;

                          public void TextScale(Slider slider)
                          {
                          text.fontSize = (int)slider.value;
                          }
                          }


                        2. Create empty GameObject. Attach ScalerScript to it and drag and drop your Text object to Text field of the script in the Inspector window:



                        enter image description here



                        enter image description here




                        1. Set Vertical Overflow to Overflow for your Text element:
                          enter image description here


                        2. 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:



                        enter image description here




                        1. Run the scene.






                        share|improve this answer























                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote











                          1. Add script:



                            using UnityEngine;
                            using UnityEngine.UI;

                            public class ScalerScript : MonoBehaviour
                            {
                            public Text text;

                            public void TextScale(Slider slider)
                            {
                            text.fontSize = (int)slider.value;
                            }
                            }


                          2. Create empty GameObject. Attach ScalerScript to it and drag and drop your Text object to Text field of the script in the Inspector window:



                          enter image description here



                          enter image description here




                          1. Set Vertical Overflow to Overflow for your Text element:
                            enter image description here


                          2. 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:



                          enter image description here




                          1. Run the scene.






                          share|improve this answer














                          1. Add script:



                            using UnityEngine;
                            using UnityEngine.UI;

                            public class ScalerScript : MonoBehaviour
                            {
                            public Text text;

                            public void TextScale(Slider slider)
                            {
                            text.fontSize = (int)slider.value;
                            }
                            }


                          2. Create empty GameObject. Attach ScalerScript to it and drag and drop your Text object to Text field of the script in the Inspector window:



                          enter image description here



                          enter image description here




                          1. Set Vertical Overflow to Overflow for your Text element:
                            enter image description here


                          2. 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:



                          enter image description here




                          1. Run the scene.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 9 at 9:28









                          Andrew Kotov

                          346210




                          346210






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Schultheiß

                              Liste der Kulturdenkmale in Wilsdruff

                              Android Play Services Check