using UnityEngine;
using System.Collections;

public class StarGen : MonoBehaviour {

	public GameObject StarPrefab;
	private GameObject Ship;

	// Use this for initialization
	void Start () {
		Ship = GameObject.Find("Ship");
		for ( int i = 0; i < 1000; i ++ ) {
			GameObject Star = GameObject.Instantiate( StarPrefab ) as GameObject;
			//float Phi = SphereRandom();
			Quaternion RandomPos = Quaternion.Euler( SphereRandom(), Random.Range( 0f, 360f), 0f );
			Star.transform.position = RandomPos*Vector3.forward*500f;
			Star.transform.parent = transform;
			Star.transform.rotation = RandomPos*Quaternion.Euler( 0f, 180f, 0 );
			Star.transform.localScale = Vector3.one*10f;
		}
	}
	
	// Update is called once per frame
	void Update () {
		transform.position = Ship.transform.position;
	}

	float SphereRandom () {
		float Theta = Random.Range( -1f, 1f ); // evenly distributed between 0 and Pi/2
		Theta = Mathf.Acos( Theta );
		Theta *= Mathf.Rad2Deg;
		return Theta-90f;
	}
}
