I am trying to make a modifiable hitbox for the player in a 2d game, and I drew a mesh like so as an example:
void DrawSideAttack()
{
Mesh m = new Mesh();
m.vertices = new Vector3[6]
{
new Vector3(rb.position.x, rb.position.y + 1f, 0f),
new Vector3(rb.position.x, rb.position.y - 1f, 0f),
new Vector3(sideAttackTransform.position.x, sideAttackTransform.position.y - 0.25f, 0f),
new Vector3(rb.position.x, rb.position.y + 1f, 0f),
new Vector3(sideAttackTransform.position.x, sideAttackTransform.position.y - 0.25f, 0f),
new Vector3(sideAttackTransform.position.x, sideAttackTransform.position.y + 0.25f, 0f)
};
m.triangles = new int[]
{
0, 1, 2, 3, 4, 5
};
m.normals = new Vector3[]
{
Vector3.forward,
Vector3.forward,
Vector3.forward,
Vector3.forward,
Vector3.forward,
Vector3.forward
};
m.colors = new Color[6]
{
Color.red, Color.red, Color.red, Color.red, Color.red, Color.red
};
Graphics.DrawMeshNow(m, Vector3.zero, Quaternion.identity);
DestroyImmediate(m);
}
I’m wondering if there is any way to use Collider2D or Physics2D to check if there is anything overlapping this mesh to deal damage to enemies.
I’m also wondering if there’s a better way to go about creating an attack with variable amounts of vertices and sizes.
Thank you!