Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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:
    89
    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?
     
unityunity