using FalcoEngine;
using System;
using System.Collections;
using System.Collections.Generic;

public class ball_s : MonoBehaviour
{
	public string color;
	private int color_int;
	
	public GameObject red;
	public GameObject green;
	public GameObject blue;
	public GameObject purple;
	public GameObject yellow;
	
	private GameObject[] all_child=new GameObject[5];
	public int index;
	public float pos;
	private float angle;
	private GameObject first_point;
	public float start_bias;
	private controller_s controller_s;
		
	void Start()
	{
		controller_s=GameObject.Find("controller").GetComponent<controller_s>();
		start_bias=-1.2f;
		first_point=GameObject.Find("first_point");
		all_child[0]=red;
		all_child[1]=green;
		all_child[2]=blue;
		all_child[3]=purple;
		all_child[4]=yellow;
		
		for(int i=0;i<5;i++)
		{
			all_child[i].enabled=false;
		}
		
		color_int=(int)Mathf.Round(FalcoEngine.Random.Range(1f,5f));
		
		
		if(color_int==1){color="red";}
		if(color_int==2){color="green";}
		if(color_int==3){color="blue";}
		if(color_int==4){color="purple";}
		if(color_int==5){color="yellow";}
		
		all_child[color_int-1].enabled=true;
	}
	
	void FixedUpdate()
	{		
		float new_x;
		float new_z;
		
		new_x=Mathf.Cos(start_bias-pos*20)*2.5f;
		new_z=Mathf.Sin(start_bias-pos*20)*2.5f;
		
		transform.position=new Vector3(first_point.transform.position.x+new_x,first_point.transform.position.y+(pos*10.7f),first_point.transform.position.z+new_z);
		
		if(controller_s.collapse==0)
		{
			pos-=0.00012f+controller_s.speed_incr;
		}
	}
	
	public void set_color(int value)
	{
		all_child[0]=red;
		all_child[1]=green;
		all_child[2]=blue;
		all_child[3]=purple;
		all_child[4]=yellow;
		
		for(int i=0;i<5;i++)
		{
			all_child[i].enabled=false;
		}	
		
		color_int=value+1;
		
		if(color_int==1){color="red";}
		if(color_int==2){color="green";}
		if(color_int==3){color="blue";}
		if(color_int==4){color="purple";}
		if(color_int==5){color="yellow";}

		all_child[value].enabled=true;
	}
}
