Using Vector3 in ViewportToWOrldPoint

I have a script that spawns spawn points. What I am trying to make happen is that a spawn point will spawn randomly (x,y) just off the screen.

The character in this small game doesn’t move but can rotate 360 degrees and enemies can randomly come at him from any direction. Im stuck here. The same thing happens everytime and its not random. I get spawners that spawn just outside the top and spawners that appear to spawn right above my character. Im obviously doing something very wrong.

public class SpawnPointController : MonoBehaviour {
	//array of our spawn points
	public GameObject[] SpawnPoints;
	//variables for spawn delay
	private float nextSpawn = 0;
	public float spawnRate = 2;
	//amount of spawners
	public int SpawnAmount = 5;
	//spawner prefab
	public GameObject SpawnPointPrefab;
	//Spawn Point Position
	public Vector3 v3Pos = new Vector3 (Random.Range(-.15f,1.15f), Random.Range(-.15f,1.15f), 19);

	// Use this for initialization
	void Start () {

	// Update is called once per frame
	void Update () {
		SpawnPoints = GameObject.FindGameObjectsWithTag("SpawnPoint");
		v3Pos = Camera.main.ViewportToWorldPoint(v3Pos);
		for (int i=0; i<SpawnAmount; i++)
			if (Time.time  > nextSpawn && SpawnAmount > 0)
				nextSpawn = Time.time + spawnRate;
				GameObject pos = SpawnPoints[Random.Range (0, SpawnPoints.Length)];
				Instantiate(SpawnPointPrefab,v3Pos, Quaternion.identity);


I spot three problems and a potential problem right away. First this line:

public Vector3 v3Pos = new Vector3 (Random.Range(-.15f,1.15f), Random.Range(-.15f,1.15f), 19);

Does not create a spawn point off the screen. For example, it could return (0.5, 0.5) and be in the middle of the screen.

Problem #2, is that you only initialize v3Pos to a viewport coordinate at the top of the file, and that initialization is only done once when the script is attached to the game object.

On line 28, you convert v3Pos to a world coordinate, but subsequent passes through Update() are passing a world coordinate to ViewportToWorldPoint().

Might I suggest the following for the generation of spawn points just outside the screen.

v3Pos = new Vector3(0.857f, 0.857f, 0.0f);
v3Pos = Quaternion.AngleAxis(Random.Range(0.0f, 360.0f), Vector3.forward) * v3Pos;
v3Pos += new Vector3(0.5f, 0.5f, 19.0f);
v3Pos = Camera.main.ViewportToWorldPoint(v3Pos);

v3Pos could be local to Update() and not a public class instance variable. This code works by creating a Vector the length from the center of the screen to just off the top right corner of the screen. Then it randomly rotates that vector and add it to the center of the screen (Viewport coordinate). Since the potential spawn points are in a circle around the origin, the spawn points will be a litte bit further from the screen when spawned on the middle of the edge. Not sure if that is a problem for you or not.