# Click event doesn't trigger when clicking

I've made some buttons on my screen to navigate to other scenes of my Unity project but the Click(string command) method doesn't trigger. I've placed a breakpoint on the bold line in code below, but the pointer never hits that point.

public class GameNavigation : MonoBehaviour
{
public void Click(string command)
{
switch (command)
{
case "again":
break;

break;

default:
break;
}
}
}

Here are also some screenshots form my Unity project.

What did I wrong?

Note one: I've made also this code that is called after the scene ends. the parameter command is always an empty string.

public void RestartLevel(string command)
{
switch (command)
{
case "again":
break;

break;

default:
break;
}
}


If I place it in a comment, I get this error:

'Player' AnimationEvent 'RestartLevel' has no receiver! Are you missing a component?

Note two: I also use a mouse down event for when the player must shoot.

Update one: by a comment below I've made this code:

public Button btnAgain;

public void Start()
{
});

});
}


The Start() method is always called, no problems with it. But the Application.LoadLevel(...) code never executes when I click on the methods. However btnMenu and btnAgain aren't null.

Update two: I've upload a zip file on my SharePoint that you can access. Start a game and choose level 01. You navigating to a new scene. On that scene you have on the right below side you have two buttons, these are the buttons that doesn't work. If you can find the problem, please give me the solving of the problem. Other bug fixes are also welcome. 😉

• For clicking event you will have to write "ButtonNam.onClick.AddListener". – Shraddha Patel Jan 4 '16 at 11:42
• Go through this and try once answers.unity3d.com/questions/938496/… – Shraddha Patel Jan 4 '16 at 11:44
• First check that the method is actually being called and with what parameter. Second, check that strings aren't immutable (which makes == not a valid comparison and you have to use .equals()). Third, if == is valid, it still may not work correctly in a switch statement. 4th, change your code to use enums so it isn't stringly typed. – Draco18s Jan 4 '16 at 16:00
• @Draco18s: The RestartLevel is always called after the last animation (this is the game over animation when the player is dead). the parameter command is in that case an empty string. – H. Pauwelyn Jan 4 '16 at 16:05
• If you're passing an empty string, then you've intentionally constructed your method to do nothing. – Draco18s Jan 4 '16 at 16:08

1. Confirm that the Clicked method is run. I suggest just putting a Debug.Log() statement there. Debug.Log(command); would be perfect, because it also lets you know the command.
2. If your Click method isn't being run, most likely something else is taking that click. Look for other objects that might be intercepting the click in front of it (Might not be visible).
3. If the correct command is received, then you should probably use .equals() for comparison. For instance, command.equals("again")