using UnityEngine;
using System.Collections;

public class BulletNoFX : MonoBehaviour {
	public float speed;
	public float life_time=1.5f;
	ExplosionPool explosionPool;

	[HideInInspector]
	public Vector3 direction;	/* should be normalized vector */
	[HideInInspector]
	public GameObject particle;

	float life_timer = 0;

	void Start() {
		explosionPool = GameObject.FindGameObjectWithTag("SmallExplosionPool").GetComponent<ExplosionPool>();
	}
	void Update () {
		CheckToDispose();
		if ( speed != 0 ) transform.position += direction*speed*Time.deltaTime;
	}

	void OnEnable() {
		gameObject.GetComponent<MeshRenderer>().enabled = true;
		life_timer = 0;
	}

	void CheckToDispose() {
		life_timer+=Time.deltaTime;
		if ( life_timer >= life_time ) { gameObject.SetActive(false); }
	}

	void OnCollisionEnter(Collision collision){
		Debug.Log("OnCollisionEnter");
		if ( collision.gameObject.CompareTag("Player" ) ) return;
		gameObject.GetComponent<MeshRenderer>().enabled = false;
		GameObject explosion = explosionPool.Get();
		explosion.transform.position = transform.position;
		explosion.particleSystem.Play();
	}
	
}
