how to make AI attack you

just wondering how to make my enemy attack me ?

Look at this

Ok I don’t really know what you are programming since you don’t comment it in your question. But in 2D I made a function to control the enemy logic adding a wait time so it doesn’t get tedious, unless you do a souls like

void EnemyLogic()
    {
        distance = Vector2.Distance(transform.position, target.position);

        if (distance > attackDistance)
        {
            StopAttack();
        }
        else if (attackDistance >= distance && cooling == false)
        {
            Attack();
        }

        if (cooling)
        {
            Cooldown();
            anim.SetBool("Attack", false);
        }
    }

You can also add a trigger zone and a hot zone, so that it detects when the player is in the enemy’s attack zone just use OnTriggerEnter2D(Collider2D collider) and compare the tag with player CompareTag("Player")) and the same with trigger area OnTriggerEnter2D(Collider2D collider)