Home c# scroll sheet in unity

scroll sheet in unity




How can you create a vertically spruce list from the buttons to Unity using UI? The number of buttons is always different and depends on the data entered by the player.

Answer 1, Authority 100%

To do this, you need to create:

  1. ScrollRect – List itself.
  2. layout group. To your taste. In your case, this is verticlaysoutgroup .
  3. Create a link between the Layout group and scrollRect . By specifying the required field in ScrollRect Our group (ScrollLect.Content ).
  4. Create child elements relative to Layout the desired buttons. button.transform.setparent (layout.transform);

You can also play with Layoutelement by adding it to your button.

Answer 2, Authority 100%

The old question, but maybe someone will enter it by searching, therefore I will answer.

Create a standard UI / Scroll view through the right mouse button in the hierarchy / any other familiar way.
On the CONTENT object hanging the [Vertical Layout Group] and [CONTENT SIZE FITER] [1]
On the root object Prefabs hang [Layout Element]

Next, the above components are set up and customize according to your requests. It depends on who should drive than.
Attached to the components of the reference to their API.

Judging by the comments that I saw from you here, you are generally interested in the ability to add objects to the list in the game process.

Classroom content that will do it looks like this:

GameObject _ButtonPrefab;
ScrollRect _ScrollRect;
Public Void CreateButton ()
  GameObject Button = Instantiate (_ButtonPrefab, False);
  var component = button.getcomponent & lt; image & gt; ();
  Component.color = Color.Red;
  Button.transform.SetParent (_ScrollRect.Content, False);

[SerializeField] – Displays the field in the editor, but leaves it private, which, unlike the Public modifier, does not break the class encapsulation
Instantiate – Creates and returns a copy of the object. There is overload – you can read the documentation.
After creating an object, you can do with it that you want, and after the setting place in the subsidiaries inside the content of the rope scrub, which automatically turns on this object to the speeding list (Vertical Layout Group) and changes its size (Content Size Fiter)

Answer 3

small tutorial [en]

https://unity3d.com/ru/ Learn / Tutorials / Topics / User-Interface-UI / UI-Scrollbar



Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions