Spawn a prefab within specific boundaries?

I’m building a basic 2D space shooter, and I’d like my enemies to spawn randomly from the top of the screen.

I know how to do that with “invokeRepeatinf”, “instantiate” and “Random.Range”. My question is:

  • How to create an invisible “spawn object” with a width and height on my scene?
  • Then how to randomly spawn my enemy prefab from within this “spawn object”?

This is how i instantiate object within boundary. you can attach this to main camera…

#pragma strict
public var enemy1AstroidPrefab : GameObject;

private var x : float;
private var y : float;
private var z : float;

    function Start () {
    function Update () {
    function CreateRandomShip()
    		x = Random.Range(-3.25f , 3.25f);
    		z = -6.72f;
    		y = 8.0f;
    		enemy1AstroidPrefab.transform.position = new Vector3(x , y , z);	

For translating object to down side here is script . Attach this to your enemy object.

#pragma strict
public var minSpeed : float ; 
public var maxSpeed : float ;

private var currentSpeed : float;
private var pos : float;

private var scoreControllerScript : ScoreController;
private var gameControllerScript : GameController;

function Update () {
	currentSpeed = Random.Range(minSpeed , maxSpeed);
	var amttomove : float = currentSpeed * Time.deltaTime;
	transform.Translate(Vector3.down * amttomove , Space.World);

Hope you get idea.