﻿using UnityEngine;
using System.Collections;

public class Crystal : MonoBehaviour {

	public float emissionRate = 0.5f;
	public float shrinkRate = 0.0001f;

	Material mat;

	// Use this for initialization
	void Start () {
		mat = GetComponent<Renderer> ().material;
	}
	
	// Update is called once per frame
	void Update () {

		float emission = Mathf.PingPong (Time.time * emissionRate, 1.0f);
		Color color = new Color (emission/8, emission/2, emission, 1.0f);
		mat.SetColor ("_EmissionColor", color);

		Vector3 newscale = transform.localScale - new Vector3(shrinkRate, shrinkRate, shrinkRate);
		transform.localScale = newscale;
	}

	void OnTriggerEnter(Collider other) {
		print (other.gameObject.tag);
		if (other.gameObject.tag == "Player") {
			other.gameObject.GetComponentInChildren<RaycastCrystals> ().crystalCount = 1000;
			Destroy (gameObject);
		}
	}
}
