Help with Void

Hi, someone can help me, Resume and Pause in the Void Uptade don’t linking in the Void Resume and Void Pause. Why?

using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using UnityEngine;

public class Pause : MonoBehaviour
{

public static bool GameIsPaused = false;

public GameObject PauseMenuUI;

}

void Resume()
{
PauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
}

void Pause()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;

}

void Update()
{
if (Input.GetKeyDown(KeyCode.P))
{
Resume();
}
else
{
Pause();
}
}

The Error CS0116: A namespace cannot directly contain members such as fields or methods

It looks like you either accidently closed off your class, thus your methods are not within the class anymore. Or you inserted an extra bracket. I suspect the first.

public class Pause : MonoBehaviour
{

public static bool GameIsPaused = false;

public GameObject PauseMenuUI;


} //This tag closes your class off.

You need to remove that tag and put it at the end of your script. The methods need to be between the class brackets.

2 Likes

This is your entire class right now:

public class Pause : MonoBehaviour
{

public static bool GameIsPaused = false;

public GameObject PauseMenuUI;


}

As far as the compiler is concerned, the rest is random garbage and is an error. Move everything inside the class.

1 Like