Skip to main content
deleted 127 characters in body
Source Link
Stephan
  • 1.7k
  • 11
  • 25

Your Pause Menu doesnt initialize anyYou are getting Null Pointer Exceptions for all of your GameObjectsthose errors.

Basically you are trying to use variables that you haven't initialized. For any private variable, you have to get a handle to the object with FindGameObject methods in your Start() before you can use it.

[SerializeField] private GameObject _attackButton;
[SerializeField] private GameObject _moveButton;
[SerializeField] private GameObject _pauseMenu;
[SerializeField] private GameObject _pauseButton;

So you're getting null pointer exceptionsYour first error, for instance is at

void Start () {
        _isPaused = false;
        _pauseMenu.SetActive(false);
    }

private void HideButtonsInitializeVariables()
{
    _attackButton.SetActive(false);
  _player = _moveButton_player.SetActiveGetComponent<PlayerController>(false);
    _pauseButton.SetActive(false);
  _requiredScore = _pauseMenu.SetActive(true);10;
}

private void ShowButtons()
{
   

_player is still null, because you havent initialized it with FindGameObject like so

GameObject _attackButtonp=GameObject.SetActiveFindWithTag(true"Player");
    _moveButton.SetActiveif(truep!=null);
    _pauseButton_player=p.SetActiveGetComponent<PlayerController>(true);
  

From that point on, you need to always preface any calls to _player with

if(_player != _pauseMenu.SetActive(falsenull);
} 

To fix, change your Start() functionIn order to FindGameObject()be safe if for each of your buttons and menus.some reason no object is tagged as Player

Your Pause Menu doesnt initialize any of your GameObjects with FindGameObject in Start().

[SerializeField] private GameObject _attackButton;
[SerializeField] private GameObject _moveButton;
[SerializeField] private GameObject _pauseMenu;
[SerializeField] private GameObject _pauseButton;

So you're getting null pointer exceptions at

void Start () {
        _isPaused = false;
        _pauseMenu.SetActive(false);
    }

private void HideButtons()
{
    _attackButton.SetActive(false);
    _moveButton.SetActive(false);
    _pauseButton.SetActive(false);
    _pauseMenu.SetActive(true);
}

private void ShowButtons()
{
    _attackButton.SetActive(true);
    _moveButton.SetActive(true);
    _pauseButton.SetActive(true);
    _pauseMenu.SetActive(false);
} 

To fix, change your Start() function to FindGameObject() for each of your buttons and menus.

You are getting Null Pointer Exceptions for all of those errors.

Basically you are trying to use variables that you haven't initialized. For any private variable, you have to get a handle to the object with FindGameObject methods in your Start() before you can use it.

Your first error, for instance is at

private void InitializeVariables()
{
    _player = _player.GetComponent<PlayerController>();
    _requiredScore = 10;
}

_player is still null, because you havent initialized it with FindGameObject like so

GameObject p=GameObject.FindWithTag("Player");
if(p!=null)
    _player=p.GetComponent<PlayerController>();

From that point on, you need to always preface any calls to _player with

if(_player != null)

In order to be safe if for some reason no object is tagged as Player

Source Link
Stephan
  • 1.7k
  • 11
  • 25

Your Pause Menu doesnt initialize any of your GameObjects with FindGameObject in Start().

[SerializeField] private GameObject _attackButton;
[SerializeField] private GameObject _moveButton;
[SerializeField] private GameObject _pauseMenu;
[SerializeField] private GameObject _pauseButton;

So you're getting null pointer exceptions at

void Start () {
        _isPaused = false;
        _pauseMenu.SetActive(false);
    }

private void HideButtons()
{
    _attackButton.SetActive(false);
    _moveButton.SetActive(false);
    _pauseButton.SetActive(false);
    _pauseMenu.SetActive(true);
}

private void ShowButtons()
{
    _attackButton.SetActive(true);
    _moveButton.SetActive(true);
    _pauseButton.SetActive(true);
    _pauseMenu.SetActive(false);
} 

To fix, change your Start() function to FindGameObject() for each of your buttons and menus.