Join Jesse Freeman for an in-depth discussion in this video Working with RectTransforms, part of Unity 5: UI.
- Now, let's talk a little bit more about direct transform that each of our UI components has. Let's go back into our UI intro scene and let's select our button. We'll also show direct transform properties in the inspector. And before we dig into this, let's switch back over to 2D mode and also focus on our button. Direct transform is made up of several properties. The most important one is going to be at the top, which is our positions, as well as the width and height.
Now, this depends a lot on how our anchors are set up. Right now, because our Rect Transform is centered, we have a position x, a position y, a position z, and a width and a height. There are templates that change the anchor presets. Each of these effect the way that our button is laid out. We're going to dive a little bit more into the anchors in the next video. But it's important to note, as you change the anchor type you may also change the way that you're able to lay out the x and y position.
If you stretch out the anchors, instead of having a distinct x, y, width and height, you might have a top, left, right, or bottom. Also, the anchors can manually be changed via the drop-down. The next thing that we should talk about is the pivot. The pivot represents the area that the UI element will rotate around or be laid out against. In this case, you can see there is a light crosshair in the middle of our button.
And that's because our pivot and our anchors are set to the middle of the button. Pivot, x, and y are a zero to one relationship. Depending on how you're laying it out, zero is on the left, or in the case of y, zero is on the bottom. And one on the x position is to the right. And on y it'll be at the top. Last is the rotation and the scale. These work exactly how you would expect them on any other transform object.
Now, in the next video, we'll dive deeper into the anchors and show you how each of the anchor types affect the layout of our element inside of the Canvas.
- 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.