Hayden
August 20, 2012, 11:29am
1
Im trying to set up this multiplayer menu and it popped up saying theres an error but i cant see one can someone help me please
using UnityEngine;
using System.Collections;
public class MenuManager : MonoBehaviour
{
public string CurrentMenu;
public string MatchName;
void Start()
{
CurrentMenu = “Main”;
}
void OnGUI()
{
if (CurrentMenu == “Main”)
Menu_Main();
if (CurrentMenu == “Lobby”)
Menu_Lobby();
if (CurrentMenu == “Host”)
Menu_HostGame();
}
public void NavigateTo(string nextmenu)
{
CurrentMenu = nextmenu;
}
private void Menu_Main()
{
GUI.Button(new Rect(10,10,200,50), “Host Game”);
{
NavigateTo(“Host”);
}
}
private void Menu_HostGame()
{
GUI.Button(new Rect(10,10,200,50), “Back”);
{
NavigateTo(“Main”);
}
GUI.Button(new Rect(10,60,200,50), “Start Server”);
{
NavigateTo(“Main”);
}
GUI.TextField(new Rect(220, 10, 200, 30),
Errors here }
private void Menu_Lobby()
{
}
}
timsk
August 20, 2012, 11:41am
2
using UnityEngine;
using System.Collections;
public class MenuManager : MonoBehaviour
{
public string CurrentMenu;
public string MatchName;
void Start()
{
CurrentMenu = "Main";
}
void OnGUI()
{
if (CurrentMenu == "Main")
Menu_Main();
if (CurrentMenu == "Lobby")
Menu_Lobby();
if (CurrentMenu == "Host")
Menu_HostGame();
}
public void NavigateTo(string nextmenu)
{
CurrentMenu = nextmenu;
}
private void Menu_Main()
{
if(GUI.Button(new Rect(10,10,200,50), "Host Game")) //GUI.Button if a method that returns a bool, needs an if block.
{
NavigateTo("Host");
}
}
private void Menu_HostGame()
{
if(GUI.Button(new Rect(10,10,200,50), "Back")) //Again... the if.
{
NavigateTo("Main");
}
if(GUI.Button(new Rect(10,60,200,50), "Start Server"))
{
NavigateTo("Main");
}
GUI.TextField(new Rect(220, 10, 200, 30),"Text here" ) //There was a comma here, we both missed it! :)
}
private void Menu_Lobby()
{
}
}
Properly formatting your code is very important, it allows you to find missing curly braces and such much easier.
Also, read up on if blocks and the GUI.Button method:
If-Statement(so SO important to learn!)
GUI.Button
Hayden
August 20, 2012, 11:47am
3
Ummm its still there
any idea why ?
timsk
August 20, 2012, 11:51am
4
I found it, it was a sneaky comma :P. I’ve updated the code above.
Hayden
August 20, 2012, 12:28pm
5
thanks dude but its still showing up
timsk
August 20, 2012, 12:44pm
6
Copy and pasting that code works fine for me. Make sure you copy it verbatim
timsk
August 20, 2012, 2:35pm
8
I said what I mean… There’s no other way to put it. The code I posted here works perfectly for me, generating no errors. Check the error that’s being generated, make sure it’s the same one.
Hayden
August 20, 2012, 4:44pm
9
These are the three errors that occur
Assets/AS Assets/Character Controllers/Sources/Scripts/ThirdPersonController.js(193,54): UCW0003: WARNING: Bitwise operation ‘|’ on boolean values won’t shortcut. Did you mean ‘||’?
Assets/Scripts/MenuManager.cs(107,1): error CS8025: Parsing error
Assets/Scripts/MenuManager.cs(97,5): error CS1525: Unexpected symbol `}’