Error CS1061

I got some error and i don’t know how to handle it, pls help:)

everything started to crash


I somehow i fixed input system error. i still got:
[{
“resource”: “/C:/Users/Flyator/Asteroid Avoider/Assets/Scripts/PlayerHealth.cs”,
“owner”: “csharp”,
“code”: “CS1061”,
“severity”: 8,
“message”: “‘GameOverHandler’ does not contain a definition for ‘EndGame’ and no accessible extension method ‘EndGame’ accepting a first argument of type ‘GameOverHandler’ could be found (are you missing a using directive or an assembly reference?) [Assembly-CSharp]”,
“source”: “csharp”,
“startLineNumber”: 10,
“startColumn”: 25,
“endLineNumber”: 10,
“endColumn”: 32
}]

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerHealth : MonoBehaviour
{
    [SerializeField] private GameOverHandler gameOverHandler;

    public void Crash()
    {
        gameOverHandler.EndGame();
        gameObject.SetActive(false);
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameOverHandler : MonoBehaviour
{
    [SerializeField] private GameObject gameOverDisplay;
    [SerializeField] private AsteroidSpawner asteroidSpawner;

    public void EndGame()
    {
        asteroidSpawner.enabled = false;
        gameOverDisplay.gameObject.SetActive(true);
    }

    public void PlayAgain()
    {
        SceneManager.LoadScene(1);
    }

    public void ReturnToMenu()
    {
        SceneManager.LoadScene(0);
    }
}

I couldnt get any Definition on “EndGame” and now it is working, how strange.

When that happens to me, it’s because Unity doesn’t recompile after I make a code change. To fix it, in the editor I find any script and right click then re-import… that’s the work around I found to make Unity recompile

It looks like solofo may be on the right track here.

If his trick doesn’t work, try closing Unity and deleting the Library folder, then going back into Unity. This will force a recompile of the entire project.

Privacy & Terms