Join Jesse Freeman for an in-depth discussion in this video Controlling a slider in scripts, part of Unity 5: UI.
- So now that we have our slider,…let's look at how to connect the slider…to a script.…In our Project folder,…let's go to our Scripts folder…and create a new C# script.…We're going to call this Slider Test…and then let's open this up in MonoDevelop.…Here, we can delete the Start and Update methods…since we won't be using them.…And now we need to create a new method…that will capture the value change…from the slider.…We'll make this public.…It'll return void…and we'll call it On Value Changed.…
It'll also accept the float…called Value…and inside of this method,…we'll create a debug log statement.…Here, we'll simply add the value…to new value string.…Let's save this and go back into Unity.…We'll select our slider…and scroll down to the bottom of the slider script.…There's already an easy way for us to connect up…the On Value Change…from the slider…but first we'll need to attach the script to our scene.…
Let's create a new game object.…We'll call this Game Logic…just like we did with our button example.…And now let's add the Slider Test to it…
- Adding new components to the Canvas
- Working with RectTransforms
- Nesting UI elements
- Adding rich text and effects to the UI
- Creating images
- Styling UI buttons
- Handling input
- Creating sliders
- Controlling the layout of the screen
- Adding toggles and dropdowns
Skill Level Intermediate
1. The Canvas
2. Working with the RectTransform
3. Working with Text
4. Working with Images
5. Working with Buttons
6. Handling UI Input
7. Working with a Slider
8. Controlling Layout
9. Toggles, Dropdowns, and the Input Field
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.