Last active
December 30, 2023 19:02
-
-
Save adekbadek/b911c618366eb02dde85 to your computer and use it in GitHub Desktop.
Show 2D Edge Collider as Gizmo, also in Edit Mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
add the "offset", then it's perfect ;)