I have components attached to a game object that I need to remove every time the level is unloaded. This is the code I have so far to find the components on the game object:
You want typeof(O_MoveTO) I think. alternatively, you could use: GetComponents<O_MoveTo> , which would return an array of components attached that match.
var components = myGameObject.GetComponents<Component>();
foreach (var component in components) {
if (!(component is O_MoveTo)) {
Debug.Log(component);
}
}
yeah “is” is for checking if types are the same. A other option would be to use the “as” keyword to try and cast the object. if the cast fails it will result in null.