Hey everybody, I'm an artist that's trying some C# scripting for a little side project and I'm having some problems.
Its becoming somewhat of a hastle to make a different function for each button. So what I want to do is make one function, OnButton, in my case and have that handle all button click requests.
What I want it to do is to go through a switch statement that checks the name of the button, "Select_Button", "Play_Button", etcetera.
But I've run into a problem that I can't seem to figure out just yet. if I put a debug.log in the Send() function of UiButtonMessage: Debug.Log("Debugging the clicked Button: " + gameObject); it returns the correct value. Eg. Select_Button or Play_Button or other button names.
As of now this is my switch statement:
public void OnButton()
{
switch(somethingShouldGoHere)
{
case "Left_Button":
Debug.Log ("pressed left button");
break;
case "Right_Button":
Debug.Log ("pressed Right button");
break;
case "Select_Button":
Debug.Log ("pressed Select button");
break;
}
}
I've tried to make a string variable in the script that holds my OnButton function and have the Send() function write the name of the gameobject in that variable but it returns as a nullreference exception.
Although scripting is kinda fun I feel I'm in way over my head and it took me about 3 hours getting nowhere before I went to sleep. I hoped getting back to it the next day would help but it didn't.
PS I'm using the free version if that matters