How to Create Button in Unity with code? Way1:Use Instantiate function. Create Button in Unity manually. Then drag it to a variable. After that, write the line such as Instantiate(obj); P.S. (1)I can not find way to set both the width and the height of the button now in this way. Way2:GUILayout.Button GUILayout is a class that can create UI Object. P.S. (1) GUILayout can be written in OnGUI function. When GUILayout was called in other function. There is an ArgumentException before play mode. (2)void OnGUI() is a built-in function. It is case-sensitive, so OnGui() was not accepted. When you override it, you will see the color of OnGUI is blue when you code in visual studio 2019. (3)When is OnGUI() invoked? it is invoked several times per frame (or per time when the event is triggered). (4)I can find way to set both the width and the height of the button now in this way. pass the width and height as argument when you call GUILayout.Button. more details on: U...