Skip to content

Instantly share code, notes, and snippets.

@adekbadek
Last active December 30, 2023 19:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save adekbadek/b911c618366eb02dde85 to your computer and use it in GitHub Desktop.
Save adekbadek/b911c618366eb02dde85 to your computer and use it in GitHub Desktop.
Show 2D Edge Collider as Gizmo, also in Edit Mode
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class visibleCollider : MonoBehaviour {
// The Collider itself
private EdgeCollider2D thisCollider;
// array of collider points
private Vector2[] points;
// the transform position of the collider
private Vector3 _t;
void Start () {
thisCollider = GetComponent ("EdgeCollider2D") as EdgeCollider2D;
points = thisCollider.points;
_t = thisCollider.transform.position;
}
void OnDrawGizmos() {
Gizmos.color = Color.blue;
// for every point (except for the last one), draw line to the next point
for(int i = 0; i < points.Length-1; i++)
{
Gizmos.DrawLine(new Vector3(points[i].x+_t.x, points[i].y+_t.y), new Vector3(points[i+1].x+_t.x, points[i+1].y+_t.y));
}
}
}
@allfake
Copy link

allfake commented Aug 4, 2015

Here is show 2d Polygon Collider https://gist.github.com/allfake/e899878b14cadf1e09d5.

@emptybraces
Copy link

add the "offset", then it's perfect ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment