- Home /
Slider.value won't change to INT
void Update () {
slider.wholeNumbers = true;
}
public void Test(){
WeaponsIndex = slider.value;
}
This is where my problem is residing in my code. I'm getting a Cannot implicitly convert type float' to
int'. An explicit conversion exists (are you missing a cast?) No matter what I do. I figured changes in the code in update that whole numbers would be true would solve it however slider.value is still a float instead of int.
Answer by DiegoSLTS · Jun 10, 2015 at 12:08 AM
If "WeaponsIndex" is an int variable, cast the float value of the slider to an int.
WeaponsIndex = (float)slider.value;
The "wholeNumbers" property doesn't change the float type of the value to an int, it just prevents the slider to move into non-integer values when moving it.
It is an int, however even the code you provided still gives the same error
Ins$$anonymous$$d of casting float, casting int worked out. so (int)slider.value
Yes, sorry! That's what I was trying to say, you cast the float value of the slider as an int to copy it into an int variable. Was writing some other stuff and got distracted here. Glad it worked somehow.
I still marked your answer right, because you saved me a major headache and helped me learn something I've never seen before
Your answer
Follow this Question
Related Questions
Getting a slider value from a different scene 1 Answer
4.6 Slider round to int? 1 Answer
Slider value not working? 0 Answers
Slider issues 1 Answer
Have a problems with a values 1 Answer