im using a box collider but i want to change its size for when a new objects equiped so i was wondering how i can change a box collider size in c#
BoxCollider b = someGameObject.collider as BoxCollider;
if(b != null)
{
b.size = new Vector(1.0f, 1.0f, 1.0f);
}
//something like this should work
In 2022, the code provided by the previous answer is no longer working. The following code worked for me:
BoxCollider col;
void Start()
{
col = GetComponent<BoxCollider>();
}
private void OnMouseDown()
{
if(col != null)
{
col.size = new Vector3(.5f, 1f, .5f);
}
}