- Home /
Slider.value error
I'm trying to access the value of a slider in the scene but every time I write .value for the variable set as a slider an error comes up saying 'Slider' does not contain a definition for 'value' and no extension 'value'. Also using UnityEngine.Ui doesn't light up in the script so it seems it's not accessing the library when I try to create a variable for a Slider. Is VisualStudio and/or Unity bugging out or am I making a mistake in my code?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerHealth : MonoBehaviour {
public float playerHealth;
private Slider slide;
private void Start()
{
slide = GetComponent<Slider>();
}
private void Update()
{
slide.value = playerHealth;
}
Can you please add some code so that we can help you better? Thanks!
Answer by WarmedxMints · Feb 28, 2019 at 11:26 PM
Do you happen to have another class called Slider in your project and it is using that instead of the one in the UI namespace?
In VS, you can place your cursor over Slider and press F12 to navigate to the class.
I see that you are using the UnityEngine.UI namespace though and the Slider class in that does have a public variable value.
Your answer
![](https://koobas.hobune.stream/wayback/20220612192705im_/https://answers.unity.com/themes/thub/images/avi.jpg)