# Slider

> Make a 3D slider that moves along one axis.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.7/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

## Slider(Vector3, Vector3)

Make a 3D slider that moves along one axis.

```csharp
public static Vector3 Slider(Vector3 position, Vector3 direction)
```

### Parameters

**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): The position of the current point in the space of [Handles.matrix](/engine/6000.7/script-reference/unityeditor/handles/matrix.md).**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): The direction axis of the slider in the space of [Handles.matrix](/engine/6000.7/script-reference/unityeditor/handles/matrix.md).

### Returns

| Type                                                              | Description                                                                                                                                                         |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Vector3](/engine/6000.7/script-reference/unityengine/vector3.md) | The new value modified by the user's interaction with the handle. If the user has not moved the handle, it will return the position value passed into the function. |

### Remarks

This method will draw a 3D-draggable handle on the screen. The handle is constrained to sliding along a direction vector in 3D space.

![SliderHandle (Slider)](/api/media?file=/engine/6000.7/media/images/SliderHandle.png)

*Slider handle in the Scene View.*

Add the following script to your Assets folder as SliderExample.cs and add the SliderExample component to an object in a Scene.

```csharp
using UnityEngine;

[ExecuteInEditMode]
public class SliderExample : MonoBehaviour
{
    public Vector3 targetPosition { get { return m_TargetPosition; } set { m_TargetPosition = value; } }
    [SerializeField]
    private Vector3 m_TargetPosition = new Vector3(1f, 0f, 2f);

    public virtual void Update()
    {
        transform.LookAt(m_TargetPosition);
    }
}
```

Add the following script to Assets/Editor as SliderExampleEditor.cs and select the object with the SliderExample component.

```csharp
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(SliderExample)), CanEditMultipleObjects]
public class SliderExampleEditor : Editor
{
    protected virtual void OnSceneGUI()
    {
        SliderExample example = (SliderExample)target;

        float size = HandleUtility.GetHandleSize(example.targetPosition) * 0.5f;
        float snap = 0.1f;

        EditorGUI.BeginChangeCheck();
        Vector3 newTargetPosition = Handles.Slider(example.targetPosition, Vector3.right, size, Handles.ConeHandleCap, snap);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(example, "Change Look At Target Position");
            example.targetPosition = newTargetPosition;
            example.Update();
        }
    }
}
```

## Slider(Vector3, Vector3, float, CapFunction, float)

Make a 3D slider that moves along one axis.

```csharp
public static Vector3 Slider(Vector3 position, Vector3 direction, float size, Handles.CapFunction capFunction, float snap)
```

### Parameters

**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): The position of the current point in the space of [Handles.matrix](/engine/6000.7/script-reference/unityeditor/handles/matrix.md).**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): The direction axis of the slider in the space of [Handles.matrix](/engine/6000.7/script-reference/unityeditor/handles/matrix.md).**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The size of the handle in the space of [Handles.matrix](/engine/6000.7/script-reference/unityeditor/handles/matrix.md). Use [HandleUtility.GetHandleSize](/engine/6000.7/script-reference/unityeditor/handleutility/gethandlesize.md) if you want a constant screen-space size.**** (\[CapFunction]\(/engine/6000.7/script-reference/unityeditor/handles/capfunction)): The function to call for doing the actual drawing. By default it is [Handles.ArrowHandleCap](/engine/6000.7/script-reference/unityeditor/handles/arrowhandlecap.md), but any function that has the same signature can be used.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The snap increment. See [Handles.SnapValue](/engine/6000.7/script-reference/unityeditor/handles/snapvalue.md).

### Returns

| Type                                                              | Description                                                                                                                                                         |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Vector3](/engine/6000.7/script-reference/unityengine/vector3.md) | The new value modified by the user's interaction with the handle. If the user has not moved the handle, it will return the position value passed into the function. |

### Remarks

This method will draw a 3D-draggable handle on the screen. The handle is constrained to sliding along a direction vector in 3D space.

![SliderHandle (Slider)](/api/media?file=/engine/6000.7/media/images/SliderHandle.png)

*Slider handle in the Scene View.*

Add the following script to your Assets folder as SliderExample.cs and add the SliderExample component to an object in a Scene.

```csharp
using UnityEngine;

[ExecuteInEditMode]
public class SliderExample : MonoBehaviour
{
    public Vector3 targetPosition { get { return m_TargetPosition; } set { m_TargetPosition = value; } }
    [SerializeField]
    private Vector3 m_TargetPosition = new Vector3(1f, 0f, 2f);

    public virtual void Update()
    {
        transform.LookAt(m_TargetPosition);
    }
}
```

Add the following script to Assets/Editor as SliderExampleEditor.cs and select the object with the SliderExample component.

```csharp
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(SliderExample)), CanEditMultipleObjects]
public class SliderExampleEditor : Editor
{
    protected virtual void OnSceneGUI()
    {
        SliderExample example = (SliderExample)target;

        float size = HandleUtility.GetHandleSize(example.targetPosition) * 0.5f;
        float snap = 0.1f;

        EditorGUI.BeginChangeCheck();
        Vector3 newTargetPosition = Handles.Slider(example.targetPosition, Vector3.right, size, Handles.ConeHandleCap, snap);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(example, "Change Look At Target Position");
            example.targetPosition = newTargetPosition;
            example.Update();
        }
    }
}
```

## Slider(int, Vector3, Vector3, float, CapFunction, float)

Make a 3D slider that moves along one axis.

```csharp
public static Vector3 Slider(int controlID, Vector3 position, Vector3 direction, float size, Handles.CapFunction capFunction, float snap)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): **** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): The position of the current point in the space of [Handles.matrix](/engine/6000.7/script-reference/unityeditor/handles/matrix.md).**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): The direction axis of the slider in the space of [Handles.matrix](/engine/6000.7/script-reference/unityeditor/handles/matrix.md).**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The size of the handle in the space of [Handles.matrix](/engine/6000.7/script-reference/unityeditor/handles/matrix.md). Use [HandleUtility.GetHandleSize](/engine/6000.7/script-reference/unityeditor/handleutility/gethandlesize.md) if you want a constant screen-space size.**** (\[CapFunction]\(/engine/6000.7/script-reference/unityeditor/handles/capfunction)): The function to call for doing the actual drawing. By default it is [Handles.ArrowHandleCap](/engine/6000.7/script-reference/unityeditor/handles/arrowhandlecap.md), but any function that has the same signature can be used.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The snap increment. See [Handles.SnapValue](/engine/6000.7/script-reference/unityeditor/handles/snapvalue.md).

### Returns

| Type                                                              | Description                                                                                                                                                         |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Vector3](/engine/6000.7/script-reference/unityengine/vector3.md) | The new value modified by the user's interaction with the handle. If the user has not moved the handle, it will return the position value passed into the function. |

### Remarks

This method will draw a 3D-draggable handle on the screen. The handle is constrained to sliding along a direction vector in 3D space.

![SliderHandle (Slider)](/api/media?file=/engine/6000.7/media/images/SliderHandle.png)

*Slider handle in the Scene View.*

Add the following script to your Assets folder as SliderExample.cs and add the SliderExample component to an object in a Scene.

```csharp
using UnityEngine;

[ExecuteInEditMode]
public class SliderExample : MonoBehaviour
{
    public Vector3 targetPosition { get { return m_TargetPosition; } set { m_TargetPosition = value; } }
    [SerializeField]
    private Vector3 m_TargetPosition = new Vector3(1f, 0f, 2f);

    public virtual void Update()
    {
        transform.LookAt(m_TargetPosition);
    }
}
```

Add the following script to Assets/Editor as SliderExampleEditor.cs and select the object with the SliderExample component.

```csharp
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(SliderExample)), CanEditMultipleObjects]
public class SliderExampleEditor : Editor
{
    protected virtual void OnSceneGUI()
    {
        SliderExample example = (SliderExample)target;

        float size = HandleUtility.GetHandleSize(example.targetPosition) * 0.5f;
        float snap = 0.1f;

        EditorGUI.BeginChangeCheck();
        Vector3 newTargetPosition = Handles.Slider(example.targetPosition, Vector3.right, size, Handles.ConeHandleCap, snap);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(example, "Change Look At Target Position");
            example.targetPosition = newTargetPosition;
            example.Update();
        }
    }
}
```

## Slider(int, Vector3, Vector3, Vector3, float, CapFunction, float)

Make a 3D slider that moves along one axis.

```csharp
public static Vector3 Slider(int controlID, Vector3 position, Vector3 offset, Vector3 direction, float size, Handles.CapFunction capFunction, float snap)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): **** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): The position of the current point in the space of [Handles.matrix](/engine/6000.7/script-reference/unityeditor/handles/matrix.md).**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): **** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): The direction axis of the slider in the space of [Handles.matrix](/engine/6000.7/script-reference/unityeditor/handles/matrix.md).**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The size of the handle in the space of [Handles.matrix](/engine/6000.7/script-reference/unityeditor/handles/matrix.md). Use [HandleUtility.GetHandleSize](/engine/6000.7/script-reference/unityeditor/handleutility/gethandlesize.md) if you want a constant screen-space size.**** (\[CapFunction]\(/engine/6000.7/script-reference/unityeditor/handles/capfunction)): The function to call for doing the actual drawing. By default it is [Handles.ArrowHandleCap](/engine/6000.7/script-reference/unityeditor/handles/arrowhandlecap.md), but any function that has the same signature can be used.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The snap increment. See [Handles.SnapValue](/engine/6000.7/script-reference/unityeditor/handles/snapvalue.md).

### Returns

| Type                                                              | Description                                                                                                                                                         |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Vector3](/engine/6000.7/script-reference/unityengine/vector3.md) | The new value modified by the user's interaction with the handle. If the user has not moved the handle, it will return the position value passed into the function. |

### Remarks

This method will draw a 3D-draggable handle on the screen. The handle is constrained to sliding along a direction vector in 3D space.

![SliderHandle (Slider)](/api/media?file=/engine/6000.7/media/images/SliderHandle.png)

*Slider handle in the Scene View.*

Add the following script to your Assets folder as SliderExample.cs and add the SliderExample component to an object in a Scene.

```csharp
using UnityEngine;

[ExecuteInEditMode]
public class SliderExample : MonoBehaviour
{
    public Vector3 targetPosition { get { return m_TargetPosition; } set { m_TargetPosition = value; } }
    [SerializeField]
    private Vector3 m_TargetPosition = new Vector3(1f, 0f, 2f);

    public virtual void Update()
    {
        transform.LookAt(m_TargetPosition);
    }
}
```

Add the following script to Assets/Editor as SliderExampleEditor.cs and select the object with the SliderExample component.

```csharp
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(SliderExample)), CanEditMultipleObjects]
public class SliderExampleEditor : Editor
{
    protected virtual void OnSceneGUI()
    {
        SliderExample example = (SliderExample)target;

        float size = HandleUtility.GetHandleSize(example.targetPosition) * 0.5f;
        float snap = 0.1f;

        EditorGUI.BeginChangeCheck();
        Vector3 newTargetPosition = Handles.Slider(example.targetPosition, Vector3.right, size, Handles.ConeHandleCap, snap);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(example, "Change Look At Target Position");
            example.targetPosition = newTargetPosition;
            example.Update();
        }
    }
}
```
