Search Unity

[solved] Hook up text to slider

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

  1. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,191
    I have been watching the "The new UI" tutorial (http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/the-new-ui) 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):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using System.Collections;
    5.  
    6. public class UpdateValue : MonoBehaviour {
    7.  
    8.     public Text text;
    9.  
    10.     public void UpdateText(float f) {
    11.         text.text = f.ToString ();
    12.     }
    13. }
    14.  
    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

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,191
    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?