You are here

18 March 2012
Simple tutorial that shows you how to create GUI button in Unity using Javascript.
Make a Scene, I called it Menu.
Create a JavaScript file, I named it MenuGUI.
Create a button. Rect makes rectangular at 0,0 two dimensional coordinates. Rectangular size is 200 pixels wide and 100 in height. OnGUI function gets iterated at every frame.
Source code viewer
  1. function OnGUI() {
  2. GUI.Button(Rect(0,0,200,100), 'Button');
  3. }
Programming Language: Javascript
Create an empty object form GameObject -> Create Empty or simply Ctrl+Shift+N. Attach the script to the empty object.
Make the button do something.
Source code viewer
  1. function OnGUI() {
  2. if(GUI.Button(Rect(0,0,200,100), 'Button')) {
  3. // Code goes here...
  4. }
  5. }
Programming Language: Javascript