using UnityEngine;
using System.Collections;

public class Lightning : MonoBehaviour {

	public GameObject castle;
	public GameObject sky;

	public Sprite sky_dark;
	public Sprite sky_lit;

	public Sprite castle_dark;
	public Sprite castle_lit;

	private bool lit;
	private int litCount;

	public int chance = 360;

	// Use this for initialization
	void Start () {
		lit = false;
		litCount = 0;
	}
	
	// Update is called once per frame
	void Update () {
		if (litCount == 20) {
			lit = false;
			litCount = 0;
			castle.GetComponent<SpriteRenderer> ().sprite = castle_dark;	
			sky.GetComponent<SpriteRenderer> ().sprite = sky_dark;
		} else if (lit) {
			litCount++;
		} else {
			if (Random.Range (0, chance) == 0) {
				lit = true;
				castle.GetComponent<SpriteRenderer> ().sprite = castle_lit;	
				sky.GetComponent<SpriteRenderer> ().sprite = sky_lit;
			}
		}
	}
}
