# Monobehaviour can not find a member OfType in Unity

This is the line where I am getting above mentioned error:

var listeners = FindObjectOfType<MonoBehaviour> ().OfType<iPlayerRespawnListener> ();


I have already imported these libraries including System.Linq which has the above mentioned method OfType:

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


Where is it going wrong and how to fix this?

To expand on OP's answer: the crucial difference is the use of FindObjectOfType versus FindObjectsOfType.
• FindObjectOfType returns a single object.
• FindObjectsOfType returns an array of objects.
Linq's OfType extension method requires an enumerable collection (such as an array), which is why you were seeing that error and why switching calls fixed it.
Resolved by changing FindObjectOfType to FindObjectsOfType:
var listeners = FindObjectsOfType<MonoBehaviour> ().OfType<iPlayerRespawnListener> ();