Random spawn outside viewport - Wrap around screen

I am creating an asteroids like game, and I need it to randomly place asteroids out side the viewport and apply force to the rigidbody2d in the direction of the viewport. For one how would I do this and where should I put the script? Thank You!!

P.S. I have an asteroid prefab.

bool isWrappingX = false;
	bool isWrappingY = false;
	bool isVisible = true;
	float transportcooldown;

	// Use this for initialization
	void Start () {

	}


	// Update is called once per frame
	void Update () {
		transportcooldown--;

		screenWrap ();
		var cam = Camera.main;
		var viewportPosition = cam.WorldToViewportPoint(transform.position);

//		if (isVisible == true && viewportPosition.x > 1 || isVisible == true && viewportPosition.x < 0 ||
//		    isVisible == true && viewportPosition.y > 1 || isVisible == true && viewportPosition.y < 0) {
//			isVisible = false;
//		}

		if (viewportPosition.x > 1 || viewportPosition.x < 0 ||
			viewportPosition.y > 1 || viewportPosition.y < 0) {
			isVisible = false;
		} else if (isVisible == false) {
			isVisible = true;
		}



	}

	void screenWrap()
	{
		if (transportcooldown > 0) {
			return;
		}

		if(isVisible)
		{
			isWrappingX = false;
			isWrappingY = false;
			return;
		}
		if(isWrappingX && isWrappingY) {
			return;
		}
		var cam = Camera.main;
		var viewportPosition = cam.WorldToViewportPoint(transform.position);
		var newPosition = transform.position;
		if (!isWrappingX && (viewportPosition.x > 1.1 || viewportPosition.x <-0.1))
		{
			newPosition.x = -newPosition.x;
			isWrappingX = true;

		}
		if (!isWrappingY && (viewportPosition.y > 1.1 || viewportPosition.y <-0.1))
		{
			newPosition.y = -newPosition.y;
			isWrappingY = true;

		}
		transform.position = newPosition;
		transportcooldown = 20;
	}

Look up the Instantiate function on how to create copies of an object in the scene, and you’ll probably want to also check Coroutines for looping and spawning in parallel.

Rigidbody has functions to apply force and you can check out Vector3 or Vector2 functions to figure out the direction you need.

Finally, you can put the script on an empty GameObject, or even in your Camera for these cases where you have systems running without a specific game object to be attached to.

screenwrap() doesnt seem to account for the

if(!isVisible) condition.

Outside viewport?  ->   isVisible = false;

screenwrap();

            ( isWrappingX = false;
             isWrappingY = false; )

if (!isWrappingX && (viewportPosition.x > 1.1 || viewportPosition.x <-0.1))
     { //Wrapping false and outside viewport

BUT, you already moved it

var newPosition = transform.position;

So

( isWrappingX = false;
  isWrappingY = false; ) //remains