using UnityEngine;
using System.Collections.Generic;

public class DelayedDamage : MonoBehaviour
{
	public float damageCountdown = 2.00f;
		
	public BaseObject damageSrc;
	public Vector3 damageSourcePt;
	public float damageAmount;
	
	public bool working = true;

	void Start()
	{
		if (working && GetComponent<Player>() != null)
		{
			GetComponent<Player>().Damage(damageSrc, damageSourcePt, damageAmount);
			working = false;
		}
	}

	void Update()
	{
		damageCountdown -= Time.smoothDeltaTime;
		if (damageCountdown < 0)
		{
			if (working && GetComponent<City>() != null)
			{
				Color c = GetComponent<SpriteRenderer>().color;
				c.g = 1;
				c.b = 1;
				c.r = 1;
				GetComponent<SpriteRenderer>().color = c;

				GetComponent<City>().Damage(damageSrc, damageSourcePt, damageAmount);
				working = false;
			}
		}

		if (working && GetComponent<City>() != null)
		{
			Color c = GetComponent<SpriteRenderer>().color;
			float gb = Mathf.Clamp01(Mathf.Sin(Time.time * 6.28f * 4)) * 0.8f;
			c.g = gb;
			c.b = gb;
			GetComponent<SpriteRenderer>().color = c;
		}
	}
}
