Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved need help with a speed bar that has a scroll wheel controlled slider

Discussion in 'Editor & General Support' started by LBardmask, Aug 9, 2020.

  1. LBardmask

    LBardmask

    Joined:
    Feb 23, 2016
    Posts:
    3
    Ok I've looked everywhere for tutorials and examples, but all I find are health bars and sliders for settings. what im trying to accomplish is a speed bar that has a fill bar (actual speed controlled by acceleration variable) and a slider (selected speed controlled by scroll wheel with a min and max variable) similar to the one found in x3 tc/ap.
    in the image shown below
    1306917001_preview_20180220204443_1.jpg
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    In what way are these not just standard filled images and sliders? If you're hoping to find some specific control that looks exactly like you want, it probably doesn't exist, and you'll need to make it yourself. I don't see why you can't use a filled image for your speed bar, along with a slider whose background you make transparent, so it's just the floating handle.
     
  3. LBardmask

    LBardmask

    Joined:
    Feb 23, 2016
    Posts:
    3

    im not looking to make it look like it, just the function of the bar. what im trying to do is make the slider handle move independantly from the fill bar. say i max the bar out with the handle. i want the fill bar to move to max at a slow speed rather than be glued to the handle.
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    A "fill bar" is easily created by adding an Image, and setting its Image Type to Filled. You can use that as your fill bar. You'd set the fill amount to some value from 0 to 1 to fill the area:

    upload_2020-8-9_19-57-55.png

    Then, for your slider, add a Slider control, then just disable all of the visual elements other than the handle itself. It will still be constrained to the width of the slider, but it sounds like you don't want to see the slider's background, just the handle:

    upload_2020-8-9_20-1-47.png

    So now you've got a fill bar, independent from a slider. Then you'd just write whatever logic that makes one of these controls affect the other. For example, in your Update statement, you could gradually adjust the fill bar's Fill Amount until it matches the slider's value by adding or subtracting a small amount each frame.
     
    LBardmask likes this.
  5. LBardmask

    LBardmask

    Joined:
    Feb 23, 2016
    Posts:
    3

    thanks thats what i was looking for, but now i feel stupid because what you described was making a custom slider with code from scratch rather than using a script to modify an existing one.it seems obvious now. its one of them days where even making coffee seems like rocket science. thank you