Adding a box collider to an object in csharp script

How do I add a box collider to an object in csharp script ?
using this code for instance :


Does not give me access to the center property that I want.

You can add any components to a gameobject by using a function GameObject.AddComponent()

There are two versions of this function: generic and not.

//Returns object that you can cast to BoxCollider
var boxCollider1 = (BoxCollider) level001cube001.AddComponent("BoxCollider");

//Returns BoxCollider
var boxCollider2 = level001cube001.AddComponent<BoxCollider>();

So, to have access to any properties of BoxCollider class you should use generic version of the function or cast to BoxCollider a result of non-generic version.

“In C# Script” as requested:

BoxCollider _bc = (BoxCollider)level001cube001.gameObject.AddComponent(typeof(BoxCollider)); =;

A way of doing this is without code.
Create a sprite, with animations.
add to it every Component that you will need along the way.
than open the “Animation” window Press “Add Property” and than you can add and control the behavior of all components on every fame.

 eg. lets say that the gravity should only start when the sprites gets to its final frame.
 Select "Add Property -> RigidBody2d ->is Kinematic 
 and take the last key-frame back one frame.
 which means that as long as the animation didn't enter its final frame the Sprite will not fall, and only on the last frame the gravity will start to affect the sprite.`enter code here`