Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Albert-han · Jun 27, 2014 at 03:54 AM · errortutorialunexpectedyoutube

Unexpected Error

Hi guys i've been following a tutorial from thefacegrabber on youtube and as far as i know i followed everything exactly the same but i get 6 errors now like.

Assets/Scripts/Network/Menu.cs(45,15): error CS1525: Unexpected symbol private' Assets/Scripts/Network/Menu.cs(51,18): error CS1519: Unexpected symbol if' in class, struct, or interface member declaration

Assets/Scripts/Network/Menu.cs(51,30): error CS1519: Unexpected symbol (' in class, struct, or interface member declaration Assets/Scripts/Network/Menu.cs(51,40): error CS1519: Unexpected symbol 0' in class, struct, or interface member declaration

Assets/Scripts/Network/Menu.cs(52,37): error CS1519: Unexpected symbol `Main' in class, struct, or interface member declaration

Assets/Scripts/Network/Menu.cs(54,35): error CS8025: Parsing error

Here's my code.I tried fixing it but I got even more errors.Could anyone please help me.Thanks

 using UnityEngine;
 using System.Collections;
 
 public class Menu : MonoBehaviour {
     
     private string CurMenu;
     public string Name;
     public string MatchName;
     public int Players;
     // Use this for initialization
     void Start () {
         CurMenu = "Main";
         Name = PlayerPrefs.GetString("PlayerName");
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     
     void ToMenu(string menu){
         CurMenu = menu;
     }
     void OnGUI(){
         if (CurMenu == "Main")
             Main();
         if (CurMenu == "Host")
             Host();
         if (CurMenu == "Lobby")
             Host();
     }
     private void Main(){
         //if (GUI.Button(new Rect (0, 0, 128, 32), "Host A Match")) {
         //    ToMenu ("Host");
         //}
         if(GUI.Button(new Rect(0,0,128,32),"Host a match")){
             ToMenu("Host");
         Name = GUI.TextField (new Rect (130, 0, 128, 32), Name);
         if (GUI.Button(new Rect (260, 0, 128, 32), "Save")) {
             PlayerPrefs.SetString ("PlayerName", Name);
             
         }
     }
     
     private void Host(){
         if(GUI.Button(new Rect(0,0,128,32),"Start")){
             NetworkManager.Instance.StartServer(MatchName,Players);
             ToMenu("Lobby");
         }
 
         if(GUI.Button(new Rect(0,33,128,32),"Back")){
             ToMenu("Main");
         }
             MatchName = GUI.TextField(new Rect(130,0,128,32),MatchName);
             GUI.Label(new Rect(260,0,128,32),"Match name");
             Players = Mathf.Clamp(Players,0,32);
             GUI.Label(new Rect(260,0,128,32),"Max Players");
             if (GUI.Button (new Rect (222, 33, 32, 32),"+"))
                  Players ++;
             GUI.Label (new Rect (192, 33, 64, 32), Players.ToString());
             if (GUI.Button (new Rect (282, 33, 32, 32),"-"))
                  Players --;
     }
 
     private void Lobby(){
         if(GUI.Button(new Rect(Screen.width - 128,Screen.height - 64,128,32),"Start")){
 
         }
         
         if(GUI.Button(new Rect(Screen.width - 128,Screen.height - 32,128,32),"Back")){
             ToMenu("Host");
         }
     }
     private void MatchList()
     {
         if (GUI.Button(new Rect(0,33,128,32), "Refresh")
         {
             MasterServer.PollHostList();
         }
         if (GUI.Button(new Rect(0,33,128,32), "Back")
         {
             ToMenu ("Main");
         }
         GUILayout.BeginArea(new Rect(Screen.width/ 2, 0, Screen.width / 2, Screen.height), "Server List");
         foreach (HostData hd in MasterServer.PollHostList())
         {
             GUILayout.BeginHorizontal();
             GUILayout.Label(hd.gameName);
             if(GUILayout.Button ("Connect"))
             {
                 Network.Connect(hd);
                 ToMenu("Lobby");
             }
             GUILayout.EndHorizontal();
         }
         GUILayout.EndArea();
     }
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by mattyman174 · Jun 27, 2014 at 03:57 AM

 private void Main()

This method has one to few closing braces.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Mehul-Rughani · Jun 27, 2014 at 06:04 AM

Try This..

using UnityEngine; using System.Collections;

public class Menu : MonoBehaviour {

 private string CurMenu;
 public string Name;
 public string MatchName;
 public int Players;
 // Use this for initialization
 void Start () {
     CurMenu = "Main";
     Name = PlayerPrefs.GetString("PlayerName");
 }
 
 // Update is called once per frame
 void Update () {
     
 }
 
 void ToMenu(string menu){
     CurMenu = menu;
 }
 void OnGUI(){
     if (CurMenu == "Main")
         Main();
     if (CurMenu == "Host")
         Host();
     if (CurMenu == "Lobby")
         Host();
 }
 private void Main(){
     //if (GUI.Button(new Rect (0, 0, 128, 32), "Host A Match")) {
     // ToMenu ("Host");
     //}
     if(GUI.Button(new Rect(0,0,128,32),"Host a match")){
         ToMenu("Host");
         Name = GUI.TextField (new Rect (130, 0, 128, 32), Name);
         if (GUI.Button(new Rect (260, 0, 128, 32), "Save")) {
             PlayerPrefs.SetString ("PlayerName", Name);
             
         }
     }
 }
     
     private void Host(){
         if(GUI.Button(new Rect(0,0,128,32),"Start")){
             NetworkManager.Instance.StartServer(MatchName,Players);
             ToMenu("Lobby");
         }
         
         if(GUI.Button(new Rect(0,33,128,32),"Back")){
             ToMenu("Main");
         }
         MatchName = GUI.TextField(new Rect(130,0,128,32),MatchName);
         GUI.Label(new Rect(260,0,128,32),"Match name");
         Players = Mathf.Clamp(Players,0,32);
         GUI.Label(new Rect(260,0,128,32),"Max Players");
         if (GUI.Button (new Rect (222, 33, 32, 32),"+"))
             Players ++;
         GUI.Label (new Rect (192, 33, 64, 32), Players.ToString());
         if (GUI.Button (new Rect (282, 33, 32, 32),"-"))
             Players --;
     }
     
     private void Lobby(){
         if(GUI.Button(new Rect(Screen.width - 128,Screen.height - 64,128,32),"Start")){
             
         }
         
         if(GUI.Button(new Rect(Screen.width - 128,Screen.height - 32,128,32),"Back")){
             ToMenu("Host");
         }
     }
     private void MatchList()
     {
         if (GUI.Button(new Rect(0,33,128,32), "Refresh"))
             {
             MasterServer.PollHostList();
         }
         if (GUI.Button(new Rect(0,33,128,32), "Back"))
             {
             ToMenu ("Main");
         }
         GUILayout.BeginArea(new Rect(Screen.width/ 2, 0, Screen.width / 2, Screen.height), "Server List");
         foreach (HostData hd in MasterServer.PollHostList())
         {
             GUILayout.BeginHorizontal();
             GUILayout.Label(hd.gameName);
             if(GUILayout.Button ("Connect"))
             {
                 Network.Connect(hd);
                 ToMenu("Lobby");
             }
             GUILayout.EndHorizontal();
         }
         GUILayout.EndArea();
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Nightdr · Jun 27, 2014 at 04:10 AM

The problem was that you were not closing your Main() method so you need to insert a "}" on there, and on lines 76 and 80 you didn't put enough ")" symbols to close the GUI.Button syntax. Here is your code fixed: using UnityEngine; using System.Collections;

 public class Menu : MonoBehaviour {
     
     private string CurMenu;
     public string Name;
     public string MatchName;
     public int Players;
     // Use this for initialization
     void Start () {
         CurMenu = "Main";
         Name = PlayerPrefs.GetString("PlayerName");
     }
     
     // Update is called once per frame
     void Update () {
         
     }
     
     void ToMenu(string menu){
         CurMenu = menu;
     }
     void OnGUI(){
         if (CurMenu == "Main")
             Main();
         if (CurMenu == "Host")
             Host();
         if (CurMenu == "Lobby")
             Host();
     }
     private void Main(){
         //if (GUI.Button(new Rect (0, 0, 128, 32), "Host A Match")) {
         //  ToMenu ("Host");
         //}
         if(GUI.Button(new Rect(0,0,128,32),"Host a match")){
             ToMenu("Host");
             Name = GUI.TextField (new Rect (130, 0, 128, 32), Name);
             if (GUI.Button(new Rect (260, 0, 128, 32), "Save")) {
                 PlayerPrefs.SetString ("PlayerName", Name);    
             }
         }
     }
     private void Host(){
         if(GUI.Button(new Rect(0,0,128,32),"Start")){
             NetworkManager.Instance.StartServer(MatchName,Players);
             ToMenu("Lobby");
         }
 
         if(GUI.Button(new Rect(0,33,128,32),"Back")){
             ToMenu("Main");
         }
         MatchName = GUI.TextField(new Rect(130,0,128,32),MatchName);
         GUI.Label(new Rect(260,0,128,32),"Match name");
         Players = Mathf.Clamp(Players,0,32);
         GUI.Label(new Rect(260,0,128,32),"Max Players");
         if (GUI.Button (new Rect (222, 33, 32, 32),"+")){
             Players ++;
         }
         GUI.Label (new Rect (192, 33, 64, 32), Players.ToString());
         if (GUI.Button (new Rect (282, 33, 32, 32),"-")){
             Players --;
         }
     }
 
     private void Lobby(){
         if(GUI.Button(new Rect(Screen.width - 128,Screen.height - 64,128,32),"Start")){
 
         }
 
         if(GUI.Button(new Rect(Screen.width - 128,Screen.height - 32,128,32),"Back")){
             ToMenu("Host");
         }
     }
     private void MatchList(){
         if (GUI.Button(new Rect(0,33,128,32), "Refresh")){
             MasterServer.PollHostList();
         }
         if (GUI.Button(new Rect(0,33,128,32), "Back")){
             ToMenu ("Main");
         }
         GUILayout.BeginArea(new Rect(Screen.width/ 2, 0, Screen.width / 2, Screen.height), "Server List");
         foreach (HostData hd in MasterServer.PollHostList()){
             GUILayout.BeginHorizontal();
             GUILayout.Label(hd.gameName);
             if(GUILayout.Button ("Connect")){
                 Network.Connect(hd);
                 ToMenu("Lobby");
             }
             GUILayout.EndHorizontal();
         }
         GUILayout.EndArea();
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Ngoc Ngo · Jun 27, 2014 at 06:04 AM

You need a "}" after line 37.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

string comparisons 2 Answers

Plug in for tutorial videos 1 Answer

Space Shooter - NullReferenceException on Scene Reload 0 Answers

Javascript literal error: unexpected identifier 1 Answer

Script not working 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges