Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Apolo435 · Feb 06, 2017 at 04:39 AM · c#unity 5noob

Unexpected Symbol 'break'

Hi I'm new in programming and there is this Unexpected Symbol 'break' that doesn't want get out no matter how many posts I read and tweaks I do. Here it is:

     void Update () 
     {
         switch (state)
 
         {
         case 0:
             if (GUI.Button (new Rect (10, 10, 100, 30), "Connect"))
             Connect ();
     break;
 
         case 1:
             (GUI.Label (new Rect (10, 10, 100, 30), "Connected"))
     break;   <----------------<-------------------<-----------------------<---------------------
         }
     }

Comment
Add comment · Show 1
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 Apolo435 · Feb 06, 2017 at 12:00 AM 0
Share

Here is the full coding using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class Game$$anonymous$$anager : Photon.$$anonymous$$onoBehaviour {
 
     public GameObject[] Spawns;
 
     public int state = 0;
 
     void Connect()
     {
         PhotonNetwork.ConnectToBestCloudServer ("V0.1");
         state = 1;
     }
 
     void Start () 
     {
         
     }
 
     void Update () 
     {
         switch (state)
 
         {
         case 0:
             if (GUI.Button (new Rect (10, 10, 100, 30), "Connect"))
             Connect ();
     break;
 
         case 1:
             (GUI.Label (new Rect (10, 10, 100, 30), "Connected"))
     break;
         }
     }
 }
 

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Pengocat · Feb 06, 2017 at 04:53 AM

You are missing a semicolon in case 1. Note that the extra parenthesis is unnecessary for this line GUI.Label (new Rect (10, 10, 100, 30), "Connected");. You could make an enum instead of setting a "magic" integer number as state.

     public GameObject[] Spawns;
     private enum ConnectionState
     {
         waitingToConnect,
         connecting,
         connected
     }
     private ConnectionState connectionState = ConnectionState.waitingToConnect;
     public bool isATestBool;
 
     // OnGUI is called for rendering and handling GUI events
     void OnGUI()
     {
         switch (connectionState)
         {
             case ConnectionState.waitingToConnect:
                 if (GUI.Button(new Rect(10, 10, 100, 30), "Connect"))
                     connectionState = ConnectionState.connecting;
                 break;
             case ConnectionState.connecting:
                 GUI.Label(new Rect(10, 10, 100, 30), "Connecting");
                 TryToConnect();
                 break;
             case ConnectionState.connected:
                 GUI.Label(new Rect(10, 10, 100, 30), "Connected");
                 //Invoke("TestReset", 3f);
                 break;
             default:
                 Debug.LogErrorFormat("connectionState not properly set in class:{0}", this);
                 break;
         }
     }
 
     private void TryToConnect()
     {
         // TODO Replace isTestBool with a photon callback that confirms the connection
         if (isATestBool )
         {
             // Connection succeeded
             connectionState = ConnectionState.connected;
         }
         else
         {
             // Still waiting for connection to complete
             connectionState = ConnectionState.connecting;
         }
     }
 
     //private void TestReset()
     //{
     //    connectionState = ConnectionState.waitingToConnect;
     //}

I left some test code in it that you could experiment with. Note the TODO comment. You should get a confirmation from photon that you got a connection before you display it. isATestBool should be replaced by your own bool check.

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 AR_Rizvi · Feb 06, 2017 at 05:28 AM

What you are trying to do is not breaking the line which is in your second case you should use ; or semicolon to break a line if you are done with it and please use Curly brackets after all if statements it is good practice

Here i have edited it

   void Update() 
      {
          switch (state)
  
          {
          case 0:
              if (GUI.Button (new Rect (10, 10, 100, 30), "Connect"))
              {
              Connect ();
              }
      break;
  
          case 1:
            GUI.Label (new Rect (10, 10, 100, 30), "Connected");
 
      break;
          }
      }
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

9 People are following this question.

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

Related Questions

FormatException: Input string was not in the correct format 0 Answers

What is wrong with my rotation code? (i am new to coding) 1 Answer

What is wrong with my script? 0 Answers

Particles appearing behind background image 0 Answers

how do i remember a just instantiated prefab as a variable gameobject? 1 Answer


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