Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Anyway to fill in the square gizmos for BoxCollider2D?

Discussion in 'Scripting' started by MagicCancel, Jan 16, 2018.

  1. MagicCancel

    MagicCancel

    Joined:
    Jul 30, 2015
    Posts:
    25
    Would be very helpful.
     
  2. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,739
    use a gizmo, on a script attached the same the object as your collider you could try something like this

    Code (CSharp):
    1.     private void OnDrawGizmos() {
    2.         var collider = GetComponent<BoxCollider>();
    3.         if (collider == null) return;
    4.  
    5.         var matrix = transform.localToWorldMatrix;
    6.         Gizmos.matrix = matrix;
    7.  
    8.         Gizmos.color = TRIGGER_COLOR;
    9.         Gizmos.DrawCube(collider.center, collider.size);
    10.     }
    11.  
    this is code i did for a BoxCollider, but it should work more or less fine with BoxCollider2D if you Get that instead of the BoxCollider
     
  3. MagicCancel

    MagicCancel

    Joined:
    Jul 30, 2015
    Posts:
    25
    Thanks a ton!