P
P
Pavel Subbotin2020-11-15 20:26:22
Unity
Pavel Subbotin, 2020-11-15 20:26:22

How to create a button through Unity script?

How to create multiple buttons in a panel with Grid Layout using a script? I also used this script, but the button is created larger than the whole screen:

GameObject btn = new GameObject();
btn.AddComponent<CanvasRenderer>();
btn.AddComponent<Image>();
btn.AddComponent<Button>();
btn.transform.parent = panel.transform;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Makov, 2020-11-16
@Paul_Dizer

I don’t know exactly how, but in the code I don’t see any reference to Grid Layout at all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question