#pragma strict
var MovingObjects: GameObject[];
var ShouldSpawn: boolean;
var db:dbAccess;

function Start () {
	ShouldSpawn = false;
}

function Update()
{
	if(MainSettings.GetToLoad() > 0)
	{
		db = GameObject.FindGameObjectWithTag("MainCamera").GetComponent(dbAccess);	
		ShouldSpawn = true;
			
			/*Clear all on screen*/
				var Objects: GameObject[] = GameObject.FindGameObjectsWithTag("obstacle");
				for(var go:GameObject in Objects)
				{
					Destroy(go);
				}
				
				Objects = GameObject.FindGameObjectsWithTag("fuel");
				for(var go:GameObject in Objects)
				{
					Destroy(go);
				}
				
				Objects = GameObject.FindGameObjectsWithTag("invincibility");
				for(var go:GameObject in Objects)
				{
					Destroy(go);
				}
					
			/*Spawn game objects*/
			//Obstacles
			
			var x:float;
			var y:float;
			var z:float;
			
			var gameobjects: Array;	
			
			var counter: int = 1;
			for(var Mo: GameObject in MovingObjects)
			{
				gameobjects= db.LoadGameObjects(counter);
				for(var g:Array in gameobjects)
				{
					x = parseFloat(g[0].ToString());
					y = parseFloat(g[1].ToString());
					z = parseFloat(g[2].ToString());
		
					var rotation:GameObject = GameObject.FindGameObjectWithTag("5sp");
					Instantiate(Mo, Vector3(x,y,z), rotation.transform.rotation);
				}
				counter++;
			}
			MainSettings.SetToLoad(-1);
		
	}
	else
	{
		
	}
	
	
	
}

function FixedUpdate()
{

}