Created
November 13, 2023 16:34
-
-
Save cfazilleau/5109394c104d8c5c68c36fb3e7a8f183 to your computer and use it in GitHub Desktop.
Simple Visualizer for the AreaEffector2D component in unity
This file contains 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; | |
[ExecuteAlways] | |
[RequireComponent(typeof(AreaEffector2D))] | |
public class AreaEffector2DVisualizer : MonoBehaviour | |
{ | |
public float length = 5f; | |
public float arrowSize = 1f; | |
public Color color = new Color(1f, .5f, 0f); | |
private AreaEffector2D effector = null; | |
private void OnDrawGizmos() | |
{ | |
effector ??= GetComponent<AreaEffector2D>(); | |
if (effector) | |
{ | |
Vector3 position = transform.position; | |
Vector3 direction = new Vector3(Mathf.Cos(effector.forceAngle), Mathf.Sin(effector.forceAngle)); | |
Vector3 normal = new Vector3(direction.y, -direction.x); | |
Gizmos.color = color; | |
Gizmos.DrawLine(position, position + direction * length); | |
Gizmos.DrawLine(position + direction * length, position + direction * (length - arrowSize) + normal * arrowSize); | |
Gizmos.DrawLine(position + direction * length, position + direction * (length - arrowSize) - normal * arrowSize); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment