Resizing colliders at runtime

Hi,

I’ve been trying to resize a BoxCollider at runtime, but I’ve been unable to do so.

From the research I’ve made, I found this forum thread that speaks of exactly the issue I’m having.

The thing is that I can’t understand how they were able to solve their problem.

TL;DR: What do they mean by: getting the specific collider instance, and update its properties.

  • How do I get the instance?
  • How do I update its properties?

Thanks for your time.

Get the instance:

BoxCollider col = (BoxCollider)yourGameObject.collider;

Updating properties:

col.size = new Vector3(10, 10, 10);

Untested but should work.

I tried this and this is the syntax error it read:
A field initializer cannot reference the nonstatic field, method, or property

I can’t figure this one out either…