Search Unity

Is the bounds.size and the GetComponent.BoxCollider2D.size of a GameObject meant to be the same?

Discussion in 'Scripting' started by egonspengler_84, Apr 8, 2021.

  1. egonspengler_84

    egonspengler_84

    Joined:
    Jan 26, 2021
    Posts:
    153
    I have a script attached to a GameObject with the following code:


    Code (CSharp):
    1. public class Player: MonoBehaviour{
    2.  
    3. private BoxCollider2D _col2D;
    4.  
    5. void Start(){
    6.  
    7.     _col2D = GetComponent<BoxCollider2D>();
    8.  
    9. }
    10.  
    11. void Update(){
    12.  
    13.  
    14. Debug.Log("The size of the Bounding Box equals: " + _col2D.bounds.size);
    15. Debug.Log("The size of the BoxCollider2D equals: " +_col2D.size);
    16.  
    17. }
    18.  
    I would have thought that "_col2D.bounds.size" and "_col2D.size" would output the exact same thing however when I run this code it outputs the following to the console:


    Code (CSharp):
    1. Size of Player's BoxCollider2D component is(5.2, 8.4)
    2. Size of Player's Bounding Box is(1.6, 2.6, 0.0)
    }

    Could someone help me why the Vector values of these two things are different?