using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RandomStartPos : MonoBehaviour
{

    public float xrange = 9;
    public float yrange = 5;

    public Vector2 origin;
    public float minDistFromOrigin = 4.5f;

    private float DistanceToOrigin()
    {
        return Vector2.Distance(transform.position, origin);
    }

    void Start()
    {
        int tries = 0;
        do
        {
            transform.position = new Vector3(Random.Range(-xrange, xrange), Random.Range(-yrange, yrange), 0);
            tries++;
        } while (DistanceToOrigin() < minDistFromOrigin && tries < 40);
    }
}
