# Trying to move slider based off percentage of screen

So I am trying to modify a slider’s value based off of the percentage of the screen that you have moved across. I want if you are at a x pixel less than 100 the slider value will be 0 and if you are a x pixel greater 1820 you will be at max value. If you are at any other value I want the normalizedValue of the slider to be set to FingerXPos/(Screen.width-200) . At least I think that math is right. I want the slider’s touch area to start at 100 and end at 1820. If the user’s previous x pos is less than the x pos that represents where the handle currently is which I am trying to calculate by doing float CurrentXSliderPos = ((Screen.width-200) * SliderNormalizedValue)+100 and the current finger x pos is greater than the current x slider pos or the previous x pos is greater than the current x slider pos and the current finger x pos is less than the current x pos I update the normalizedValue of my slider. Now my problem is this seems to work great for increasing the slider’s value but when I try to decrease it goes up once instead of going down. I’m not sure how to fix it. Any and all help is appreciated. Below is my current code for updating the value of my slider.

``````private void TPUpdateValue()
{
float SliderNormalizedValue = SliderObj.normalizedValue;
float CurrentXSliderPos = ((Screen.width-200) * SliderNormalizedValue)+100;
if(FingerXPos>=100 && FingerXPos<=1820 && ( (PrevFingerXPos < CurrentXSliderPos && FingerXPos >= CurrentXSliderPos) || (PrevFingerXPos > CurrentXSliderPos && FingerXPos <=CurrentXSliderPos) ) )
{
SliderObj.normalizedValue = FingerXPos / (Screen.width-200);
}
else if (FingerXPos < 100 && ( (PrevFingerXPos < CurrentXSliderPos && FingerXPos >= CurrentXSliderPos) || (PrevFingerXPos > CurrentXSliderPos && FingerXPos <= CurrentXSliderPos) ) )
{
SliderObj.normalizedValue = 0;
}
else if (FingerXPos >1820 && ((PrevFingerXPos < CurrentXSliderPos && FingerXPos >= CurrentXSliderPos) || (PrevFingerXPos > CurrentXSliderPos && FingerXPos <= CurrentXSliderPos) ) )
{
SliderObj.normalizedValue = 1;
}
}
``````

This looks like a mess. Maybe try Unity - Scripting API: Camera.WorldToViewportPoint