- Home /
C# access slidervalue
What i'm doign wrong, i dont get it! It tells me:
LevelMenu.cs: error CS1061: Type Slider' does not contain a definition for
value' and no extension method value' of type
Slider' could be found (are you missing a using directive or an assembly reference?)
The public transfrom sensiSlider is a Canvas UI slider element..
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class LevelMenu : MonoBehaviour {
public Transform sensiSlider;
public float hSliderValue;
public void storeOptions(){
hSliderValue = sensiSlider.GetComponent<Slider>().value;
}
}
Answer by Bunny83 · Jun 28, 2015 at 09:00 AM
You most likely have named a script and / or class of yourself "Slider". Rename that file / class to something different or use
sensiSlider.GetComponent<UnityEngine.UI.Slider>().value;
btw: You should declare your public variable like this:
public Slider sensiSlider;
and reassign the reference by drag&drop the slider again onto the variable. That way you don't need the GetComponent call at all. This of course won't solve the ambiguous naming issue but simplifies the script and even runs faster.
Oh my god, you are totally right. While testing i copied over a script from the net that was called Slider.
I the beginning i had written public Slider sensiSlider, but i couldn't drag & drop the Slider in that slot... now after deleting the script everything works fine!!!
Thanks alot for that!