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
-1
Question by Sassieee · Aug 16, 2014 at 08:47 AM · error

Error in line (86,14), I can't figure out what it is...

 using System.Collections;
 using UnityEngine;
 
 //List of all the posible gamestates
 public enum GameState
 {
     NotStarted,
     Playing,
     Completed,
     Failed
 }
 
 //Make sure there is always an AudioSource component on the GameObject where this script is added.
 [RequireComponent(typeof(AudioSource))]
 public class GameManager : MonoBehaviour
 {
     //Text element to display certain messages on
     public GUIText FeedbackText;
 
     //Text to be displayed when entering one of the gamestates
     public string GameNotStartedText;
     public string GameCompletedText;
     public string GameFailedText;
 
     //Sounds to be played when entering one of the gamestates
     public AudioClip StartSound;
     public AudioClip FailedSound;
 
     private GameState currentState = GameState.NotStarted;
     //All the blocks found in this level, to keep track of how many are left
     private Block[] allBlocks;
     private Ball[] allBalls;
 
     // Use this for initialization
     void Start()
     {
         //Find all the blocks in this scene
         allBlocks = FindObjectsOfType(typeof(Block)) as Block[];
 
         //Find all the balls in this scene
         allBalls = FindObjectsOfType(typeof(Ball)) as Ball[];
 
         //Prepare the start of the level
         SwitchTo(GameState.NotStarted);
     }
 
     // Update is called once per frame
     void Update()
     {
         switch (currentState)
         {
             case GameState.NotStarted:
                     //Check if the player taps/clicks.
                     if (Input.GetMouseButtonDown(0))    //Note: on mobile this will translate to the first touch/finger so perfectly multiplatform!
                     {
                         for (int i = 0; i < allBalls.Length; i++)
                             allBalls[i].Launch();
 
                         SwitchTo(GameState.Playing);
                     }
                 break;
             case GameState.Playing:
                 {
                     bool allBlocksDestroyed = true;
 
                     //Check if all blocks have been destroyed
                     for (int i = 0; i < allBlocks.Length; i++)
                     {
                         if (!allBlocks[i].BlockIsDestroyed)
                         {
                             allBlocksDestroyed = false;
                             break;
                         }
                     }
 
                     //Are there no balls left?
                     if (FindObjectOfType(typeof(Ball)) == null)
                         SwitchTo(GameState.Failed);
 
                     if (allBlocksDestroyed)
                         SwitchTo(GameState.Completed);
                 
                 break;
             if (GameState.Failed){
                 Application.LoadLevel("Menu")
             if (GameState.Completed){
                 Application.LoadLevel("Level 2")
 
                 //Check if the player taps/clicks.
                 if (Input.GetMouseButtonDown(0))    //Note: on mobile this will translate to the first touch/finger so perfectly multiplatform!
                     Restart()
             break;
         }
     }
 
     //Do the appropriate actions when changing the gamestate
             public void SwitchTo(GameState newState);
         currentState = newState;
 
         switch (currentState)
         {
             default:
             case GameState.NotStarted:
                 DisplayText(GameNotStartedText);
                 break;
             case GameState.Playing:
                 audio.PlayOneShot(StartSound);
                 DisplayText("");
                 break;
             case GameState.Completed:
                 audio.PlayOneShot(StartSound);
                 DisplayText(GameCompletedText);
                 StartCoroutine(RestartAfter(StartSound.length));
                 break;
             case GameState.Failed:
                 audio.PlayOneShot(FailedSound);
                 DisplayText(GameFailedText);
                 StartCoroutine(RestartAfter(FailedSound.length));
                 break;
         }
 
     //Helper to display some text
     private void DisplayText(string text)
     {
         FeedbackText.text = text;
     }
 
     //Coroutine which waits and then restarts the level
     //Note: You need to call this method with StartRoutine(RestartAfter(seconds)) else it won't restart
     private IEnumerator RestartAfter(float seconds)
     {
         yield return new WaitForSeconds(seconds);
 
         Restart();
     }
 
     //Helper to restart the level
     private void Restart()
     {
         Application.LoadLevel(0);
     }
         }
Comment
Add comment · Show 2
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 Kiwasi · Aug 16, 2014 at 08:51 AM 0
Share

Please provide the exact error message

avatar image Nick4 · Aug 16, 2014 at 09:05 AM 0
Share

Oh, the horror.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by tanoshimi · Aug 16, 2014 at 08:52 AM

Every error has an error code and description that tells you what the problem is. It would be helpful if you include them next time....

In this case, it appears that you've got some messed up syntax in your switch statement in Update() (did you change a series of if/elses to a switch, perhaps?)

 switch(currentState) {
 ...
   if (GameState.Failed){
     Application.LoadLevel("Menu")
   if (GameState.Completed){
     Application.LoadLevel("Level 2")
 ...}
  

should be:

 switch(currentState) {
 ...
 case GameState.Failed:
     Application.LoadLevel("Menu");
 
 case GameState.Completed: 
     Application.LoadLevel("Level 2");
 ...}
 

to match the syntax of the previous gamestate cases.

Comment
Add comment · Show 5 · 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 Sassieee · Aug 16, 2014 at 09:16 AM 0
Share

But know I have unexpected symbol 'case' (87,14)

 switch(currentState) {
 
         case GameState.Failed:
                 Application.LoadLevel("$$anonymous$$enu")
         case GameState.Completed:
                 Application.LoadLevel("Level 2")
             
avatar image Bunny83 · Aug 16, 2014 at 11:25 AM 0
Share

tanoshimi is right, however C# doesn't allow you to fall through a case. So you have to put a break at the end of each case (right before the next case starts). just like the other cases before

avatar image gjf · Aug 16, 2014 at 11:39 AM 0
Share

AND you'll need to add a semicolon onto the end of each of those loads (as they were in tanoshimi's code!)

avatar image Sassieee · Aug 16, 2014 at 03:01 PM 0
Share

Can you give an example, i don't know exactly what you mean...

avatar image meat5000 ♦ · Aug 16, 2014 at 06:31 PM 0
Share

http://msdn.microsoft.com/en-GB/library/06tc147t.aspx

avatar image
0

Answer by screenname_taken · Aug 16, 2014 at 08:56 AM

My guess is either an else, or most probably you need a } for the if statement at that line.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

When I kill one enemy, the rest disapear, but still shoot 1 Answer

Solve me this unexpected token error? 0 Answers

Old Script errors messing up a new scene 1 Answer

Error or Bug in unity 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