Skip to content

Instantly share code, notes, and snippets.

@andreiagmu
Forked from adekbadek/showedgecollider.cs
Created December 30, 2023 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreiagmu/981ce720d156f1b9c002e303470d3b81 to your computer and use it in GitHub Desktop.
Save andreiagmu/981ce720d156f1b9c002e303470d3b81 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));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment