Error CS0023: Operator '!' cannot be applied to operand of type 'UnityEngine.GameObject[]'

Error CS0023: Operator ‘!’ cannot be applied to operand of type ‘UnityEngine.GameObject[]’

Hello guys,
I’m learning how to use unity and I came up with a annoying error that I can’t seem to find an answer. This is the part of the code that has an error and the objective is if it can’t find an object with that tag then spawns it however it gives the error above. I would really appreciate if someone could give me a hand.

`
Transform musicPrefab;

void Start () 
{
	currentScore = 0;

	if (!GameObject.FindGameObjectsWithTag ("MM"))
	{
		var mManager = Instantiate (musicPrefab, transform.position, Quaternion.identity); //Spawns the music
	}
}

`

This isn’t a Unity issue, its a C# issue.

You are using GameObject.FindGameObjectsWithTag… PLURAL… objectS… This returns an array of GameObject (even if that array is 0 or 1 length), and you can’t just use the not equal (!) operator against a collection.

If you really are looking for a collection to be equal, then you need to iterate over the collection, use linq, write a custom class/comparer, etc… OR if you are actually just looking for a singleton GameObject, use GameObject.FindGameObjectWIthTag (no S)…

Cheers!