How would i go about implementing a melee system in a 2.5d game

So what i have in this 2.5d game is a simple movement and jump script and i would like to try and implement a melee script that can attack both left and right smoothly and make it so that it does damage but i don’t know where to start.

This is my script:

public Transform playertrn;
public Rigidbody playerRB;
public int speed;
private bool isFalling = false;
private bool doubleJump = false;
public Vector3 JumpHeight = new Vector3 (0, 8, 0);

void Start () 
{
	playertrn = GetComponent<Transform> ();
	playerRB = GetComponent<Rigidbody> ();
	Physics.gravity = new Vector3(0, -11.0F, 0);
}


void Update () 
{
	if (Input.GetKey (KeyCode.D)) 
	{	
		playertrn.Translate (new Vector3(speed, 0, 0) * speed * Time.deltaTime);
	}

	if (Input.GetKey (KeyCode.A)) 
	{
		playertrn.Translate (new Vector3 (-speed, 0, 0) * speed * Time.deltaTime);
	}

	if (Input.GetKey (KeyCode.Space) && !isFalling) 
	{
		playerRB.velocity = JumpHeight;
		isFalling = true;
	}

}
void OnCollisionStay ()
{
isFalling = false;
}
}

would i be able to get some advice on where to start with the melee system please

Thanks in advance

The way I do my melee systems is by spawning a box collider, or box collider 2D in your case, where the attack is supposed to be happening. The enemy then has a hitbox that registers OnTriggerEnter() and lowers the enemy’s health, knockback, etc. The “attack box”, let’s call it, can carry any info you’d like such as amount of damage and who sent the attack, which can then be transmitted to the enemy using OnTriggerEnter().

There are other ways to do it but this is my personal favorite. Another way is using raycasts I think.

Best of luck,
Areleli Games