using UnityEngine;
using System.Collections;

public class Particula : MonoBehaviour {

    public int countCollision = 0;
    public int collisionThreshold = 15;
    public float speed = 15;
    Rigidbody2D rigid;

    //Particula destruida pelo filho, que contem o sprite

    // Use this for initialization
    void OnEnable () {
        rigid = GetComponent<Rigidbody2D>();
        rigid.velocity = transform.up * speed;
	}
	
	// Update is called once per frame
	void Update () {
	    
	}

    // When collides with triggers check if is an Atom
    void OnTriggerEnter2D(Collider2D other) {
        if (other.gameObject.CompareTag("Atom")) {
            countCollision++;
            if (countCollision >= collisionThreshold) {
                //gameObject.SetActive(false);
                Destroy(gameObject);
            }
        }
    }

    //Gets destroyed after COLLISIONTHRESHOLD collisions
    void OnCollisionEnter2D(Collision2D other) {
        countCollision++;
        if (countCollision >= collisionThreshold) {
            //gameObject.SetActive(false);
            Destroy(gameObject);
        }
    }
}
