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 CraftyMaelyss · Jul 23, 2016 at 10:42 AM · c#pause menu

Pause Menu C# Script error CS1519: Unexpected symbol in class, struct, or interface member declaration

I'm having some trouble trying to get my script working for my pause menu after following this half hour long tutorial: https://www.youtube.com/watch?v=dvyiQLkaMcg and this isn't the first time I've encountered issues with a script after following online tutorials. I've followed it to exactly match their script but I think there's something I might be missing, here's the scrip in case someone can spot where I've gone wrong:

using UnityEngine; using UnityEngine.UI; using System.Collections;

public class UIManager : MonoBehaviour {

 public class GameObject PauseMenu;

     public bool isPaused;

 public object PauseMenu { get; private set; }

 // Use this for initialization
 void Start()
 {
     isPaused = false;
 }

 // Update is called once per frame
 void Update()
 {
     if (isPaused)
     {
         PauseGame(true);
     }
     else
     {
         PauseGame(false);
     }

     if (Input.GetButtonDown("Cancel"))
     {
         SwitchPause();
     }
 }

 void PauseGame(bool state)
 {
     if (state)
     {
         PauseMenu.SetActive(true);
         Time.timeScale = 0.0f; //This pauses the Game
     }
     else
     {
         Time.timeScale = 1.0f; //This unpauses the Game
     }
     PauseMenu.SetActive(false);
 }

 public void SwitchPause()
 {
     if (isPaused)
     {
         isPaused = false; //Changes the value
     }
     else
     {
         isPaused = true;
     }
 }

}

I would really appreciate help on this because after spending hours searching and checking my script I still can't figure out what's wrong with it P:

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by IronarmGames_LLC · Jul 23, 2016 at 11:24 AM

@CraftyMaelyss ,it seems you are defining a class incorrectly as such in your public class GameObject PauseMenu line.

To define a class for c# as a Monobehaviour in Unity, normally you would want to do it as such:

 using UnityEngine;
 using System.Collections;
 
 public class DoSomethingClass : Monobehaviour {
     //Put some methods, variables, functions, etc inside the class
 }

Below is a simple script i whipped up that may be more what you are looking for.

 using UnityEngine;
 using System.Collections;
 
 public class PauseGameTest : MonoBehaviour {
 
     public bool isPaused;
     public GameObject pauseMenu;
     public KeyCode pauseGameKey;
 
     void Start() {
         isPaused = false;
     }
 
     void Update() {
         if (Input.GetKeyDown (pauseGameKey)) {
             if (isPaused) {
                 UnPauseGame ();
             } else {
                 PauseGame ();
             }
         }
     }
 
     void PauseGame() {
         isPaused = true;
         pauseMenu.SetActive (true);
         Time.timeScale = 0;
     }
 
     void UnPauseGame() {
         isPaused = false;
         pauseMenu.SetActive (false);
         Time.timeScale = 1;
     }
 }

It can be done more efficient with less functions and added lines of code but i think this will better illustrate the idea to you.

Let me know if you have any questions about it.

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 CraftyMaelyss · Jul 23, 2016 at 11:32 AM 0
Share

I just tried it and it didn't work :( A pop up message appeared:

"Can't add script component 'UI$$anonymous$$anager' because the script class cannot be found. $$anonymous$$ake sure that there are no compile errors and that the file name and class name match."

This seems to happen whenever I try to use any bools in my C# script P:

avatar image IronarmGames_LLC CraftyMaelyss · Jul 23, 2016 at 12:10 PM 0
Share

$$anonymous$$ake sure that there are no compile errors and that the file name and class name match.

This error seems to be related to another script you have thats trying to access a script named UI$$anonymous$$anager in order to add it to an object. So your issue is with another script in your project, not this one ive created. Create a new scene real quick to test on and drag the script here to an empty gameobject and press Play. Be sure to assign the variables that are in the inspector so you can test properly. Let me know what happens.
avatar image CraftyMaelyss · Jul 23, 2016 at 12:50 PM 0
Share

@IronarmGames_LLC I just tried it and I'm getting the exact same error as before P:

avatar image IronarmGames_LLC CraftyMaelyss · Jul 23, 2016 at 01:11 PM 0
Share

I just tested this again in an empty scene and it works flawlessly. I edited the code above for a simple fix, past that in again.

If there are any errors we'd need to see the conflicting scripts as i dont know what script would be causing that.

avatar image CraftyMaelyss IronarmGames_LLC · Jul 24, 2016 at 05:06 AM 0
Share

This isn't the first time I've experienced issues whenever I've used bools in my script, have a look at this:

http://answers.unity3d.com/questions/1216909/my-game-script-is-fine-but-im-still-getting-unexpe.html

I actually found this tutorial that actually made this work for me: https://www.sitepoint.com/adding-pause-main-menu-and-game-over-screens-in-unity/

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

204 People are following this question.

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

Related Questions

Pause Menu script not working properly 1 Answer

How to switch between Time.unscaledDeltaTime and Time.deltatime after Time.timeScale? 0 Answers

Unity Crashs When Time.timescale = 0 0 Answers

C# Disabling Camera moving while in Pause Menu 1 Answer

Help with pause menu? 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