Destroy all scripts on object.

Is there any way I can destroy all components on an object, but still keeping the Transform and the GameObject itself?

GetComponents(typeof(Component));
Will give you an array of all components on the object. Iterate over the array and call Destroy () on each item.

You could use the Destroy and GetComponent method.

Destroy(this.gameObject.GetComponent<Script1OnThisObject>()); would then destroy “Script1OnThisObject” that is on the current game object - assuming that script actually exists, that is.

This code can Destroy all component.But the component that depends on other Component don’t work.Sorry my english.

public void DestroyAllComponent1( GameObject go )
{
    var components = GetComponents<Component>();
    foreach( var t in components )
    {
        if( t is Transform )
            continue;
        Destroy( t );
    }
}