Documentation

​
​

Development

User Acquisition

Monetization

Industry

Unity Studio

Open Unity Studio

Unity Studio

​
​
Unity Studio
  • What's new in Unity Studio
  • Introduction to Unity Studio
  • Launch Unity Studio
  • Create your first Unity Studio project
  • Develop with Unity Studio
    • The Unity Studio interface
    • Save your progress
    • GameObjects
    • Assets
    • Materials
    • Scene settings
    • Logic
      • Introduction to Logic
      • Create a Logic script
      • The Logic Editor interface
      • Methods, variables, and parameters
      • Nodes
      • Logic examples
        • Use a button to transform a GameObject
        • Hide or show a User Interface (UI) element
        • Trigger an animation on key press
        • Adjust scene lighting with a button
        • Interact with an asset after an event
        • Display the name of a GameObject on hover
        • Enable or disable a property on a GameObject
        • Play audio when you click an object
        • Mute and unmute audio with the toggle element
        • Use sliders to change a material's color
    • The UI Creator
    • Animation
    • AI features
  • Collaborate in Unity Studio
  • Export drafts to the Unity Editor
  • Publish and share
  • Troubleshooting Unity Studio issues
  • Report bugs and share feedback
  • Manage your analytics and marketing preferences
  1. Unity Studio
  2. Develop with Unity Studio
  3. Logic
  4. Logic examples

Use sliders to change a material's color

Set up 3 sliders to control the red, green, and blue components of a material's color.
Read time 3 minutes
Last updated 7 months ago

Use this example to understand how to set up sliders and control a material's color.
1

Create 3 sliders in your UI Canvas

  1. Select UI Canvas in the Hierarchy panel.
  2. Right-click the UI Canvas and select UI > Slider to create a new slider.
  3. Right-click your new slider, select Duplicate, and rename the duplicate slider.
  4. Repeat step 3 so you have 3 sliders. Each slider will control one of the elements of the material's color (red, green, or blue).
2

Add a Cube object to your scene and assign a new Logic script

  1. In the Hierarchy panel, select Add (+) > Primitives > Cube.
  2. Select your new cube. The Inspector window shows.
  3. From the Inspector panel, select Add Component.
  4. In the New Logic field, give a name to your new script.
  5. Select Create and Edit. The Logic Editor opens.
3

Set up the initial logic in the Logic Editor

  1. Drag a When event listener into the Logic Editor.
  2. Add a Play starts event inside the When node.
  3. Create the following variables:

    Unique name

    Type

    Description

    red_slider
    Slider
    Control the red element of the material's color.
    green_slider
    Slider
    Control the green element of the material's color.
    blue_slider
    Slider
    Control the blue element of the material's color.
    color
    Color
    Store the changing color.
  4. Create the following method:

    Unique name

    Return Type

    Description

    Update_color
    void
    Handle the slider values and change the color.
4

Create the method node

  1. Drag the
    Update_color
    method into the Logic Editor to create an Update_color node.
  2. On the
    Update_color
    node, set wait to false (do this for every
    Update_color
    node you add).
  3. Drag a Set variable value node inside the
    Update_color
    method.
  4. Add the color > r node to the first socket and red_slider > value to the second.
  5. Repeat for color > g with green_slider > value, and for color > b with blue_slider > value.
5

Apply the color to the material

  1. Add the
    me
    variable, expand it, and select GetComponent > MeshRenderer > Material > SetColor.
  2. Type
    _BaseColor
    into the
    name
    socket.
  3. Drag the
    color
    variable into the second socket.
  4. Move this node into the
    Update_color
    method.
Example Logic script to change the material's color depending on slider values.

Example Logic script to change the material's color depending on slider values.

6

Make your script listen for slider changes

  1. Drag the
    Update_color
    method into the When node. This ensures the material starts with the same values as the sliders.
  2. Add another
    red_slider
    variable in the script, expand it, and select onValueChanged > AddListener. This node detects any time the user interacts with this slider.
  3. Drag another
    Update_color
    method into the red_slider > onValueChanged > AddListener node. When the node detects user interaction, this action updates the color with the slider's value.
  4. Repeat steps 2 and 3 for
    green_slider
    and
    blue_slider
    .
Example Logic script that shows how to detect changes of sliders.

Example Logic script that shows how to detect slider changes.

  1. Close the Logic Editor.
7

Connect your Slider references

  1. In the Hierarchy panel, select the GameObject with the attached Logic script.
  2. Drag your sliders from the Hierarchy panel into the red_slider, green_slider, and blue_slider variable references in your script component.

Additional resources

  • Logic examples
  • Slider
  • Materials

Copyright © 2026 Unity Technologies
LegalPrivacy PolicyCookiesDocumentation Terms of UseDo Not Sell or Share My Personal InformationYour Privacy Choices (Cookie Settings)

"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S and elsewhere (more info here). Other names or brands are trademarks of their respective owners.

Some pages are machine-translated for convenience, and may contain inaccuracies. In the event of conflicting information, the English version is authoritative.

  • On this page
    • Additional resources


Report a problem with this page