Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

[solved] Hook up text to slider

Discussion in 'UGUI & TextMesh Pro' started by pKallv, Aug 24, 2014.

  1. pKallv


    Mar 2, 2014
    I have been watching the "The new UI" tutorial ( and in that, around 19:40, the teacher is having a slider and text and shows how to present the slider value in the text object, to which he create/attach a script with the following code:
    Code (csharp):
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using System.Collections;
    6. public class UpdateValue : MonoBehaviour {
    8.     public Text text;
    10.     public void UpdateText(float f) {
    11.         text.text = f.ToString ();
    12.     }
    13. }
    He then goes back into Unity and run the scene and as he moves the slider the text value change. I just do not get it to work. I do not fully understand how the slider communicate with the text object as the script is attached to the text object.

    He also show another way by defining the Slider in the script but for some reason i do not get that to work either.

    I have tested this in my current project as well as, lately, in an empty project but just do not get it.

    Anyone that can share some light on this or/and point to other sources of information on this topic.
  2. pKallv


    Mar 2, 2014
    I have to apologize as when i started to test again after writing this post, I finally, for some reason, got it to work.

    Can someone please delete this post?