기술 자료

​
​

Development

User Acquisition

Monetization

산업 분야

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.
읽는 시간 3분
최근 업데이트: 7달 전

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
법률 정보개인정보 처리방침쿠키Documentation Terms of Use개인 정보 판매 또는 공유 금지개인정보 보호 선택(쿠키 설정)

'Unity', Unity 로고 및 기타 Unity 상표는 미국 및 기타 지역 내 Unity Technologies 또는 그 계열사의 상표 또는 등록상표입니다(자세한 내용은 여기에서 확인하세요). 기타 명칭 또는 브랜드는 해당 소유자의 상표입니다.

일부 페이지는 편의를 위해 기계 번역되었으며 부정확한 내용이 있을 수 있습니다. 정보가 상충되는 경우, 영어 버전을 우선으로 참조하세요.

  • 보고 있는 페이지
    • Additional resources


이 페이지의 문제 보고