attach collider

is there anyway to attach and detach colliders in run time?

Use AddComponent and Destroy respectively.

–Eric

I read this as using the transform.parent parameter to be able to say, combine object into clumps like Katamari Damacy. For that you make a GameObject and add a Collider to it. Then set that GameObjects.Transform.Parent to whatever you want to stick it to (null if you want it to move independently).

Or you can use the .enabled parameter and set it to true and false if you want to turn it on and off repeatedly, and don’t want to have to remake a new one every time. To do this add it to an empty gameObject then parent that gameObject to what you want the collider attached to (at 0,0,0 position). Then just use gameObject.enabled.

That’s because BoxCollider is a class. If you want to modify the instance of a BoxCollider that is on the gameObject you could use:

in C#:

BoxCollider boxCollider = gameObject.collider as BoxCollider;

boxCollider.size = new Vector3(/fill this in/);

You don’t want to Modify BoxCollider the class as a whole, you want to modify the particular BoxCollider that is attached to your gameObject.