Why does this script crash Unity? Also simple random 2D movement?

For some reason this script crashes Unity when I run my game. I’m trying to get some simple random 2D movement. This is my first time using coroutines so I’m sure I’m doing it wrong but I didn’t think I was doing it so wrong to get Unity to crash lol. Anyone know what’s wrong and also anybody know how to get my script doing what I want it to do?

{
    Rigidbody2D rb;
    public float moveSpeed = 10f;
    Vector2 currentPos;
    Vector2 targetPos;
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        StartCoroutine(ghostMoveRandom());
    }

    IEnumerator ghostMoveRandom()
    {
        yield return new WaitForSeconds(2);
        currentPos = new Vector2(rb.position.x, rb.position.y);
        targetPos = Random.insideUnitCircle;
        while(currentPos != targetPos)
        {
            rb.transform.Translate(targetPos);
        }
        
        StartCoroutine(ghostMoveRandom());
    }
}

The most obvious problem is that most likely currentPos will never equal targetPos, because you are never changing currentPos. I guess that you will want to move towards targetPos over several frames.

I would solve this in Update() instead to avoid coroutines, but some prefere them. (Untested code)

    Rigidbody2D rb;
    float timer = 0;
    float speed = 10;
    Vector2 currentPos;
    Vector2 targetPos;
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        targetPos = rb.position;
    }
    void Update()
    {
        currentPos = rb.position;
        timer += Time.deltaTime;
        if (timer >= 2.0)
        {
            targetPos = Random.insideUnitCircle;
            timer = 0;
        }
        rb.MovePosition(Vector2.MoveTowards(currentPos, targetPos, speed * Time.deltaTime));
    }