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 thatcoolguy34511 · May 11, 2014 at 06:54 AM · c#errorpausegame

Error CS0111

I wrote the game and came across this error:

Assets/Scripts/pauseMenu.cs(40,6): error CS0111: A member `Pausemenu.Update()' is already defined. Rename this member or use different parameter types

Here is the code of this file:

 using UnityEngine;
 using System.Collections;
 
 public class Pausemenu : MonoBehaviour {
 
 private int buttonWith = 200;
 private int buttonHeight = 50;
 private int grouoWidth = 200;
 private int groupHeight = 170;
 bool paused;
 
 void Start ()
 {
 GameObject.Find("First Person Controller").GetComponent().enabled = true;
 Time.timeScale = 1;
 
 }
 
 void Update ()
 {
 if(paused)
 {
 GUI.BeginGroup(new Rect(((Screen.groupWidth/2) - (groupWidth/2)),((Screen.groupHeight/2)),groupWidth, groupHeight));
 if(GUI.Button(new Rect(0,0,buttonWidth,buttonHeight),"Main Menu"));
 {
 Application.LoadLevel(0);
 }
 if(GUI.Button(new Rect(0,60,buttonWidth,buttonHeight,"Restart Game")));
 {
 Application.LoadLevel(1);
 }
 if(GUI.Button(new Rect(0,120,buttonWidth,buttonHeight),"Quit Game"));
 {
 Application.Quit();
 }
 GUI.EndGroup();
 }
 }
 
 void Update ()
 {
 if(Input.GetKeyUp(KeyCode.Escape))
 paused = togglePause();
 }
 
 bool togglePause()
 {
 if(Time.timeScale == 0)
 {
 GameObject.Find("Player").GetComponent().enabled = true;
 Screen.lockCrusor = true;
 Time.timeScale = 1;
 return(false);
 }
 else
 {
 GameObject.Find("Player").GetComponent().enabled = false;
 Screen.lockCrusor = false;
 Time.timeScale = 0;
 return(true);
 }
 }
 }
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
1

Answer by robertbu · May 11, 2014 at 06:56 AM

You have two Update() functions/methods. You cannot have two methods with the same signature in the same class. The solution is to copy and paste line 42 and 43 into the Update() method starting on line 19. Then delete lines 40 - 44.

Comment
Add comment · Show 3 · 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 thatcoolguy34511 · May 12, 2014 at 12:31 AM 0
Share

I'm still getting an error, do I replace the update() on line 19 completely with line 42 and 43 or do i just place it after the update()?

avatar image robertbu · May 12, 2014 at 03:40 AM 0
Share

I took a second look at your code. You have GUI calls in the first Update(). So I'm guessing that the function should be OnGUI() ins$$anonymous$$d. GUI functions can only be called from within OnGUI(). There are a number of other issues. I made some educated guesses for most of them, but you will need to review the code. The one I cannot fix is the places you use:

 GameObject.Find("Player").GetComponent().enabled = false;

This line will not compile, but I cannot say what script or class you are trying to enable/disable. It should be something like:

  GameObject.Find("Player").GetComponent<SomeClass>().enabled = false;

Where 'SomeClass' is the name of a component attached to your 'Player'.

 using UnityEngine;
 using System.Collections;
 
 public class Pausemenu : $$anonymous$$onoBehaviour {
     
     private int buttonWidth = 200;
     private int buttonHeight = 50;
     private int groupWidth = 200;
     private int groupHeight = 170;
     bool paused;
     
     void Start ()
     {
         //GameObject.Find("First Person Controller").GetComponent().enabled = true;
         Time.timeScale = 1;
         
     }
     
     void OnGUI ()
     {
         if(paused)
         {
             GUI.BeginGroup(new Rect(((Screen.width/2) - (groupWidth/2)),((Screen.height/2)),groupWidth, groupHeight));
             if(GUI.Button(new Rect(0,0,buttonWidth,buttonHeight),"$$anonymous$$ain $$anonymous$$enu"));
             {
                 Application.LoadLevel(0);
             }
             if(GUI.Button(new Rect(0,60,buttonWidth,buttonHeight),"Restart Game"));
             {
                 Application.LoadLevel(1);
             }
             if(GUI.Button(new Rect(0,120,buttonWidth,buttonHeight),"Quit Game"));
             {
                 Application.Quit();
             }
             GUI.EndGroup();
         }
     }
     
     void Update ()
     {
         if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.Escape))
             paused = togglePause();
     }
     
     bool togglePause()
     {
         if(Time.timeScale == 0)
         {
             //GameObject.Find("Player").GetComponent().enabled = true;
             Screen.lockCursor = true;
             Time.timeScale = 1;
             return(false);
         }
         else
         {
             //GameObject.Find("Player").GetComponent().enabled = false;
             Screen.lockCursor = false;
             Time.timeScale = 0;
             return(true);
         }
     }
 }
avatar image thatcoolguy34511 · May 13, 2014 at 12:06 AM 0
Share

Thanks! Work well and dandy but it instantly crashes after showing the menu.

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

20 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

string.Split('/') gets Incorect format error on run? 1 Answer

Null reference exception: Object reference not set to an instance of an object 3 Answers

Error Code CS0118 or CS0120 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