The ! operator cannot be applied to the operand of type 'method group'

I’m trying to make a train bell script, and this happens. Bascially, I want a UI button which when you click, plays a looping bell sound. But when you press it again, it stops.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class Bell : MonoBehaviour
{
	public Button yourButton;
	public bool active;
	public AudioSource sound;

	void Start()
	{
		Button btn = yourButton.GetComponent<Button>();
		btn.onClick.AddListener(() => { Clickd(); });

	}

	void Update()
	{
		if (!Clickd) 
		{
			sound.Play ();
		}
		else 
		{
			sound.Pause ();
		}

	}

	void Clickd() {
		if (!Clickd) 
		{
			Clickd = true;
		} 
		else 
		{
			Clickd = false;
		}
	}
}

Error at Line 20, Character 7.

Assets/Bell.cs(20,7): error CS0023: The ‘!’ operator cannot be applied to operand of type ‘method group’

Try this:

using UnityEngine;
using UnityEngine.UI;

public class Bell : MonoBehaviour
{
	public Button button;
	public AudioSource sound;

	bool active; // Is the bell currently ringing?

	void Start()
	{
		// The button reference is already set in the inspector,
		// no need to use GetComponent. Also, no need to use 
		// a lambda for the listener, simply pass the method group.
		button.onClick.AddListener(OnButtonClicked);
	}

	void OnButtonClicked()
	{
		// Toggle active state on and off.
		active = !active;

		if (active)
			sound.Play();
		else
			sound.Stop();
	}
}

It looks like you’ve mixed up your field name “active” and the name of the method “Clickd”. Operator ‘!’ cannot be applied, means that you are trying to get the opposite of a method group named “Clickd” when you actually wanted to check the true or false value of the field “active”.

A nice trick to toggle a boolean value is to use the active = !active idiom instead of if-else statements. Also, in your code you were calling AudioSource.Play() in every frame, which you probably don’t want to do. Instead, when switching to the active state, start playing the sound once and when switching back, stop it once.