using UnityEngine;
using System.Collections;


public class JumperBehaviour : MonoBehaviour {

	static float SHOW_TIME = 3.0f;
	static float HIDE_TIME = 2.0f;

	private float cooldown;
	private bool isActive;

	// Use this for initialization
	void Start () {
		cooldown = Time.time + Random.Range(1, 100) * 0.033f;
		isActive = true;
		setHidden(false);
	}
	
	// Update is called once per frame
	void Update () {
	
		if (cooldown < Time.time) {
			isActive = !isActive;

			if (isActive) {
				//Visualizza lo sprite
				setHidden (false);
				cooldown = Time.time + SHOW_TIME;
			} else {
				//Nascondi lo sprite
				setHidden (true);
				cooldown = Time.time + HIDE_TIME;
			}
		}
	}

	void setHidden(bool b) {
		this.renderer.enabled = b;
		this.collider2D.enabled = b;
	}

	void OnCollisionEnter2D(Collision2D coll) {

		Debug.Log(coll.gameObject.name);

		if (!isActive) {

			if (coll.gameObject.tag == "Player") {
				
				CharacterBehaviour c = (CharacterBehaviour)coll.gameObject.GetComponent(typeof(CharacterBehaviour));

				coll.gameObject.transform.position += this.transform.up;
				Debug.Log(coll.gameObject.name);
				//coll.gameObject.rigidbody2D.AddForce(new Vector2(0, 1000.0f), ForceMode2D.Force);
				//c.jump(Vector3.up, 2);
			}
		}
	}
}
