Skip to content

Instantly share code, notes, and snippets.

@cfazilleau
Created November 13, 2023 16:34
Show Gist options
  • Save cfazilleau/5109394c104d8c5c68c36fb3e7a8f183 to your computer and use it in GitHub Desktop.
Save cfazilleau/5109394c104d8c5c68c36fb3e7a8f183 to your computer and use it in GitHub Desktop.
Simple Visualizer for the AreaEffector2D component in unity
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