Calling A Method From Another Script in C Sharp

I’m trying to call a method ‘GameOver();’ from a script ‘GameMaster.’

Here’s my code:

UILabel highScore = GameObject.Find("HighScore").GetComponent<UILabel>();
highScore.text = "High Score: " + GetComponent<GameMaster>().GameOver();

As you can see on the second line of my code I’m using a GetComponent to call the script and then I reference the method.

I get an error that says Assets/nguiScore.cs(25,78): error CS0122: `GameMaster.GameOver()’ is inaccessible due to its protection level.

I would like help. Thank you for your time and have a nice day.

The GameOver method is probably “private” , try changing it to public.

The GameOver() method must have have the keyword ‘public’ in front of the method declaration to be used this way from another script. Something line:

public void GameOver() {

Make it public.

public void GameOver() { ...