- Home /
Get slider value?
I tried this, but it isnt recognizing it.
using UnityEngine;
using System.Collections;
public class Settings : MonoBehaviour {
private GameObject VolumeSliderGet;
void Start () {
VolumeSliderGet = GameObject.Find ("Volume Slider").GetComponent <Slider> ().value;
}
void Update () {
audio.volume = VolumeSliderGet.
}
}
Answer by InvincibleCat · Jan 13, 2015 at 11:12 PM
ok so it's normal. When you do
VolumeSliderGet = GameObject.Find ("Volume Slider").GetComponent <Slider> ().value;
You only get the value at the a certain time.
What you can do is:
public void OnValueChanged(float newValue)
{
audio.volume = newValue;
}
Then, back to the editor, on your Slider component, you have a property called On Value Changes.
Click on the plus button, add your script (Settings) as the target and choose the method: OnValueChanged
Cheers
never$$anonymous$$d! i had to add
using UnityEngine.UI;
after the rest of initialization and my thing worked! ill accept your answer though :)
Answer by JeevanjotSingh · Jan 14, 2015 at 01:28 PM
First declare library UI if you are in c# like
using UnityEngine.UI;
then declare a variable
public Slider sliderval;
public int slidervalint;
then in Update function
slidervalint = sliderval;
debug.log(slidervalint);
Your answer
![](https://koobas.hobune.stream/wayback/20220613180342im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Compare Slider.value to find the smallest slider ? 1 Answer
How to Make a Vertical-Scroll Number Input Field, i.e. < > Value Amount 0 Answers
how i can change value By UI slider !! 1 Answer
UI Slider Value Increases Far Too Slowly With Controller. 1 Answer
Unity: Attaching a volume control slider that doesn't always exist, to another object. 0 Answers