- Home /
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);
}
}
}
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.
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()?
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);
}
}
}
Thanks! Work well and dandy but it instantly crashes after showing the menu.
Your answer
![](https://koobas.hobune.stream/wayback/20220613144746im_/https://answers.unity.com/themes/thub/images/avi.jpg)