Hello
I am trying to create a generic method that will remove duplicate Components from a GameObject.
I get the following compile error. How can I fix this?
The type `T' must be convertible to `UnityEngine.Component' in order to use it as parameter `T' in the generic type or method
Heres my code:
public static bool removeDuplicateComponents<T>(GameObject go) {
bool hasComponent = false;
bool hasDuplicates = false;
foreach (T c in go.GetComponents<T>()) { // error line
if (!hasComponent) {
hasComponent = true;
continue;
}
Destroy(c);
hasDuplicates = true;
}
return hasDuplicates;
}