Ok so I came across this nice youtube video, did everything right , then buttons aren't working. I don't have any errors, only one but you can clear it and it unsolvable. this is the script, c# : Code (CSharp): using UnityEngine; using System.Collections; public class Menu : MonoBehaviour { private string CurMenu; // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void ToMenu(string menu){ CurMenu = menu; } void OnGUI (){ if(CurMenu == "Main") Main (); if(CurMenu == "Host") Host(); } private void Main(){ if(GUILayout.Button("Host a match")) ToMenu("Host"); } private void Host(){ } } If you can help , please
Where did you attach that script? Also, don't you need to create a rectangle or something to have the button appear?
I just followed the instructions , If you know how to solve it , please help , you can experiment on unity , write the script in c# , then attach it on to the main camera and it should work , for me it doesn't ;(
Are you seeing a button? Is that the complete code? If it is the complete code you missed to set your startvalue in CurMenu. Currently at the start its empty and no menu can get selected Code (csharp): void Start () { ToMenu("Main"); } A possible error message would be that Your class name "menu" and a variable "menu" is the same. So change one of the two to something different.
I'm guessing CurMenu has no value to start with. Menu isn't the same as menu, so that's not an issue.
That's the thing , Idk where I messed up , Idk what to do I don't understand what you're talking. Just tell me where I have to edit the code
Ok i tried the code and have seen the error message. Main() is a defined word which c#/Net is using. Otherwise only the startvalue was missing. I changed Main() to something different to remove the error. Code (csharp): using UnityEngine; using System.Collections; public class Menu : MonoBehaviour { private string CurMenu; // Use this for initialization void Start () { ToMenu("Main"); } // Update is called once per frame void Update () { } void ToMenu(string menu){ CurMenu = menu; } void OnGUI (){ if(CurMenu == "Main") MainMenu (); if(CurMenu == "Host") Host(); } private void MainMenu(){ if(GUILayout.Button("Host a match")) ToMenu("Host"); } private void Host(){ } }