change collider type

i need to change collider type but i need to be absolutly sure that none of the other functions will perform
because they are dependent on collider, i have a warning that collider is destroyed or already have meshcollider (i am changing box to mesh type) here is the function i use:

function ReplaceBoxWithMeshCollider(object : GameObject){
	
	if(object.GetComponent(Collider).GetType()==BoxCollider){
		Destroy(object.GetComponent(Collider));			
		object.AddComponent("MeshCollider");
		object.layer=0;
	}
	yield WaitForEndOfFrame();

}

is there some option that waits function to be over and then to proceed?

If you do this in the LateUpdate function then it will happen after all other updates (including physics).

OnGUI is before LateUpdate?

From the documentation:

OnGUI is called for rendering and handling GUI events.
This means that your OnGUI implementation might be called several times per frame (one call per event).

So it’ll be called when you produce an input event (not necessarily before or after LateUpdate). That’s the way I understand it anyway, I haven’t tested this.