How can I add markers to a horizontal slider?

any idea how to make markers on a horizontal slider?

alt text

I imagine it as some triangles under some certain parts of the slider, if you click them, the hSlider will be taken to the place they are marking.

They will also be needed to be created during runtime.

so, example:

var hSlider = 0;
hSlider = GUI.HorizontalSlider (Rect (20,20, 300, 30), hSlider, 0, 100);

-[you slide the slider by the slider handle]
-[you're at position 37, let's say, or 0, or 63, or 89, whatever]

if(Input.GetKeyDown(KeyCode.Space)){ //place the marker
-[marker is placed in the spot, directly under the slider handle, let's say 67 is right now the value of hSlider]
-[you decide to keep sliding, but if you press the marker under 67, the sliderHandle (and the hSlider value, ofcourse) will be taken to 67], 
-you can create mayn such markers on the hSlider during runtime

any idea hwo to solve the problem? =====================================================================



about placing buttons under the slider:
    var pos1 = 0;
    var hSlider = 0;

    function OnGUI(){
    hSlider = GUI.HorizontalSlider (Rect (0,0, 300, 30), hSlider, GUI_min, GUI_max);

    GUI.Button(Rect(pos1,10,10,10), "H");

    function Update(){
          pos1 = hSlider-5; //half of the button's width

I get the button slightly missplaced.

if it's in the centre, it's allright:alt text

as it goes to the sides - it gets missplaced more and more. alt text

Interesting question. I am not an artist so I didn't make any triangles. However, I place some buttons instead (you can override the GUI style yourself, and tweak the magic constants a bit that are related with the GUI style size for the button).

Screenshot of it in action

Below script in action.

using System.Collections.Generic;
using UnityEngine;

public class Bookmarks : MonoBehaviour
    List<float> markers = new List<float>();
    float sliderValue = 0.0f;
    float sliderValueMax = 100.0f;
    Rect sliderRect = new Rect(20, 20, 500, 20);

    void Update()
        if (Input.GetKeyDown(KeyCode.Space))

    void OnGUI()
        var sliderStyle = new GUIStyle("horizontalslider");       

        var extraPadding 
            = sliderStyle.border.horizontal 
            + sliderStyle.margin.horizontal 
            + sliderStyle.padding.horizontal;

        var y = sliderRect.y + sliderRect.height;

        foreach (var marker in markers)
            var progress = marker / sliderValueMax;
            var xMin = sliderRect.xMin;
            var xMax = sliderRect.xMax - extraPadding;
            var x = Mathf.Lerp(xMin, xMax, progress);
            var rect = new Rect(x, y - 6, 12, 18);

            if (GUI.Button(rect, string.Empty))
                sliderValue = marker;

        sliderValue = GUI.HorizontalSlider(sliderRect, sliderValue, 0, 

It should run out of the box if you place it on a game object. Make sure you match the class and file names.

You could store the marker positions in a dynamic container, such as the generic List container.

When the space bar (or whatever) is pressed, add the current value of 'hSlider' to the list. (You might want to skip it if there's already an entry in the list with close to the same value.) Then, in OnGUI(), iterate over the list and create a Button() control for each entry in the list. (You'll have to map the values in the list to appropriate 'x' coordinates in GUI space.) If the corresponding button is clicked, set 'hSlider' to the value of the current entry in the list.