using UnityEngine;
using System.Collections;

[RequireComponent(typeof(ParticleSystem))]
public class BulletFX : MonoBehaviour
{
	public float life_time=1.5f;
	Vector3 _d;
	public Vector3 direction {
		set{
			_d = value;
			transform.rotation = Quaternion.LookRotation(value,Vector3.up);
		}
		private get {
			return _d;
		}
	}
	
	float life_timer = 0;


	void Update () {
		CheckToDispose();
	}
	
	void OnEnable() {
		life_timer = 0;
	}
	
	void CheckToDispose() {
		life_timer+= Time.deltaTime;

		if ( life_timer >= life_time ) {
			gameObject.SetActive(false);
		}
		if ( !particleSystem.IsAlive() ) { 
			gameObject.SetActive(false);
		}
	}
	

	void OnParticleCollision(GameObject other) {
		if ( other.CompareTag("Enemy") ) {
			other.GetComponent<TEST_MobCube>().CollideWithParticle();
		}
	} 
}

