using UnityEngine;
using System.Collections;

public class CarScript : MonoBehaviour {
	
	
	public BatteryHolderScript[] batteryHolders;
	
	public Light[] lights;
	
	public Material[] litMats;
	
	
	private bool theEnd = false;
	
	// Update is called once per frame
	void Update () {
	
		bool allCharged = true;
		
		for (int i=0; i<batteryHolders.Length; i++){
			if (!batteryHolders[i].gotBattery) allCharged = false;
		}
		
		if (allCharged){
			for (int i=0; i<lights.Length; i++){
				lights[i].enabled = true;
			}
			renderer.materials = litMats;
			if (!theEnd){
				GameObject.Find("Player").GetComponent<PlayerScript>().theEnd = true;
				GameObject.Find("Player").GetComponent<PlayerScript>().endFadeStart = Time.time + 15f;
				theEnd = true;
			}
		}else{
			for (int i=0; i<lights.Length; i++){
				lights[i].enabled = false;
			}
		}
		
	}
}
