So I'm trying to make a game with a title screen that you click to load the scene called Game
. The button that I am using, created in the editor, doesn't work for whatever reason. When I create the button using code (Below), it does work. Why can't I use the editor to create my button and then call a function using OnClick
by assigning it in the editor?
If I am going about making a 'click to play' title screen wrong please help me. Thanks in advance!
GUI.Button(new Rect(Screen.width * .25, Screen.height * .4, Screen.width * .5, Screen.height * .1), "Test")
I solved the problem by making an empty GameObject and adding a box collider and a script. The script just calls an OnClick
event like so:
function OnClick {
//Code goes here
}
Hope this helped!