- Home /
BoxCollider size
Why this don't work
BoxCollider col = go.AddComponent<BoxCollider();
col.size.z = 0.01f;
Instead I must do this in that way:
Vector3 colSize = col.size;
colSize.z = 0.01f;
col.size = colSize;
Comment
Answer by whydoidoit · Sep 09, 2012 at 12:31 PM
The reason is that size is a struct and not a class and so the value is passed by value and not by reference. When you do col.size you have a copy of the size so changing its z affects the copy which is then discarded.