Slider and Input Field Value Updates

I am wondering about how to setup a slider and an input field to take values from each other based on whichever one is receiving input.

I found this code that will pass slider data from the slider to the input field :

     using UnityEngine;
     using System.Collections;
     using UnityEngine.UI;
     public class SliderWithValue : MonoBehaviour {
         public Slider slider;
         public Text text;
         public string unit;
         public byte decimals = 2;
         void OnEnable () 
         void OnDisable()
         void ChangeValue(float value)
             text.text = value.ToString("n"+decimals) + " " + unit;

— from this discussion: @maikkel

I am wondering how add conditional to allow inputs into the input field to update the slider and slider inputs to update the input field text.

I want to continue to use the editor to drag and drop targets but after adding

public InputField input;

Now I am stuck…

Anybody out there that knows how to write this?

thank you


In the input field, only allow numbers to be entered. Then you set a callback of the input field on value changed to a public function like InputValueChanged.

Inside InputValueChanged do something like if (slider.value != float.parse(input.value)) slider.value = float.parse(input.value);