How to: Dynamic Scroll View in Unity

preview_player
Показать описание
Learn how to make a dynamically sized scroll view UI in Unity Canvas easily.

ᐅGet the full Source Code Bundle to my Unity Tutorials 🤓

📥 Get the FULL Source Code 📥

Wishlist my new game BUMBI on Steam!

🤝 Support Me 🤝

First we need to add a scroll view to our scene, then under the Content gameobject you can add your item prefabs that will be in your scrollview. To make it dynamically resize the content of the Rect Transform based on the number of items, you either add a Horizontal Layout Group or a Vertical Layout Group to the Content Gameobject along with a Content Fitter component set to Preferred setting. Then to dynamically load objects in through code you can get a reference to your prefab, the list of items or images you want to spawn, loop over them and spawn them under the Content transform, and do other processing.

►🔗 Relevant Video Links 🔗
►Kenney UI Pack: Space Expansion
►Kenney Pixel Shmup

►⏱️ Timestamps ⏱️
0:00 Intro
0:05 Set up ScrollView
1:42 Horizontal Layout Group
3:53 Content Fitter
5:48 Dynamically Add Items Through Code
10:31 IPointerClickHandler
11:19 Outro

💖💖THANK YOU TO ALL MY PATRONS 💖💖

❯❯❯ My Links ❮❮❮
💗 Patreon 💗
💬 Discord Server 💬
🐦 Twitter 🐦
📚 Facebook 📚

👍 Like and Subscribe! 👍

🖥️ Computer Setup 🖥️
*As an Amazon Associate I earn from qualifying purchases.

#unity3d #unitytutorial #gamedevelopment
Рекомендации по теме
Комментарии
Автор

Scrolling is great, but don't scroll past the subscribe button and forget to press it ❤️

samyam
Автор

Super clean and straight to the point. I'll be referencing this video a LOT in the future!

seanloughran
Автор

For anyone having the same issue as me: padding, spacing and all dinamic settings weren't working no my prefab.

I realized that the problem is that my prefab was an empty gameObject with another gameObjects as childs, and the image source for them was on spriteRenderer, but in order to work on scrollView, the objects must be Canvas Images, so go to UI->Image to create your image prefabs.

GabrielGcbs
Автор

Finally Samyam to the rescue, I cannot believe how small things like pivots fall out of my mind.

ShinichiKudoQatnip
Автор

Very clean, understandable and straight to the point. Love it, keep it up.

peterferencz
Автор

Wow. This video covered a lot of gaps in my knowledge. Subbed for sure.

obsleet
Автор

This is an amazing tutorial. I didn't even know Unity had these features. It's so very easy.

gllmusic
Автор

this is eerily close to what i was looking for. good tempo, too!

Omphaloskopie
Автор

Thanks for the great tutorial, with this and your other video about creating a leaderboard it helped me understand how to create a dynamically loading leaderboard!

These have been super helpful and I know I can use your content as resources in the future

Moondog
Автор

Thank you Samyam, I was actually thinking about doing something with scrolling recently.

AllOfTheAbove
Автор

Another great video, Sam! I keep forgetting about those IPointerXxx interfaces, thanks for the reminder!

pixelshenanigans
Автор

thank you, the Layout Groups solved my issue I was trying to solve!

CHTux
Автор

Just what I needed for my internship project!!! Thankss

nikunjsaraf
Автор

SO COOL, It helped me a lot but would be cooler if you would explain how to add more items like 2x2 instead to 1x10

uhrcru
Автор

Can you show us how to add scroll view when we have large number of objects? Like dynamically display only few on screen

santoshnalla
Автор

actually you could serialize and instantiante items not as gameObject but as ScrolViewItem, in this case you don't need to tryGetcomponent method and acces to properties and methods directly.

gamogis
Автор

It's a bit more complicated, but could you please teach how to make a book interface with page turning animation? Something like some games do (Skyrim I remember does)

ligofleyens
Автор

Nice. That's exactly what I was looking for🥳

mariokartgameplay
Автор

Praise you, oh, wise keeper of unity secrets and all things unknown! A lamb shall be offered in your name.

PICHONLINX
Автор

Thank you! this is what i'm looking for 😁

HausCoding