﻿using UnityEngine;
using System.Collections;

public class Banana : MonoBehaviour {

	bool captured = false;

	void Update() {
		transform.Rotate (Vector3.right * 90 * Time.deltaTime);
		transform.Rotate (Vector3.up * 90 * Time.deltaTime);
		if (captured)
			transform.Translate (Vector3.up * 10 * Time.deltaTime);
	}

	void OnTriggerEnter(Collider other) {
		if (other.tag == "Player") {
			captured = true;
			other.GetComponent<Player> ().bananaCount++;
			print (other.GetComponent<Player> ().bananaCount);
			StartCoroutine( DestroyBanana(1.0f) );
		}
	}

	IEnumerator DestroyBanana(float wait) {
		yield return new WaitForSeconds (wait);
		Destroy (gameObject);
	}
}
