using UnityEngine;
using System.Collections;

public class WalkerEye : MonoBehaviour {

	LightColour col;
	public Walker_S owner;
	public ColourChanger ColorSwapper;
	public string debugger;
	public void SetColour(LightColour newCol){
		col = newCol;
		debugger = col.GetColourAsString();
		ColorSwapper.SelectTexture(col);
	}
	
	void HitByLaser(Laser_S hittingLaser){
		LightColour resi_col = hittingLaser.GetCol();
		
		if(resi_col.Equals(col)){
			Instantiate(References.dieEffectObj, transform.position, Quaternion.identity);
			owner.LoseEye();
			Destroy(gameObject);
		}else{
		
			Vector3 resi_dir = hittingLaser.GetDir();
			resi_dir.x *= -1 + Random.value*2-1f;
			resi_dir.y *= -1+ Random.value*2-1f;
			resi_dir.z *= -1 + Random.value*2-1f;
			
			Vector3 resi_hit = hittingLaser.GetHit();
			
			LightColour new_col = ColourCalc.MixColours(resi_col, col);
			
			
			GameObject laser = Instantiate(References.laserObj, resi_hit, Quaternion.LookRotation(resi_dir)) as GameObject;
			Laser_S laser_script = laser.GetComponent(typeof(Laser_S)) as Laser_S;
			laser_script.SetColour(new_col);
			laser_script.SetLifetime(2f);
			laser_script.SetSource(gameObject, false);
		}
		
		
	}
	public void LightColorPaddle(){
		References.SetFlashingColor(col.GetColourAsString());
	}
}
