M
M
madhowrad2021-11-26 10:16:39
C++ / C#
madhowrad, 2021-11-26 10:16:39

How to create copies of an object under the desired object? Unity?

How to create copies of an object under the desired object? Unity?
I have a code and an object of type Text UI
Here is the code where you need to create:

foreach (var lesson in lessons)
        {
            _teachersText.text = $"{lesson.Teacher} д{lesson.Day} у{lesson.LessonNumber} каб.{lesson.ClassRoom}";
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GFX Data, 2021-11-26
@madhowrad

If you need a simple list, you can use the simple VerticalLayout UI component. You can already add text elements to it by instance, it will align all the elements in height and width. More or less like this:

public RectTransform layoutRoot;
public GameObject textPrefab;

foreach (var lesson in lessons)
{
    var go = Instance(textPrefab);
    var text = go.GetComponent<Text>();
    text.text = $"{lesson.Teacher} д{lesson.Day} у{lesson.LessonNumber} каб.{lesson.ClassRoom}";
    go.transform.SetParent(layoutRoot);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question