﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ProjectileCont : MonoBehaviour {

	public float FirePower = 1000f;
	public float FuelLevel = 100f;
	public GameObject ExplosionObj;
	public GameObject ExplosionForce;

	private bool Detonate = false;
	// Use this for initialization
	void OnEnable () {
		Vector3 TempVec = this.transform.rotation * Vector3.forward;
		this.GetComponent<Rigidbody> ().AddForce (TempVec* FirePower, ForceMode.Impulse);
	}

	void OnCollisionEnter(Collision TheContact){

		if (TheContact.gameObject.CompareTag("BuildingWall")) {
//		print ("Detonate");
			if (Detonate == false) {
				Detonate = true;
				Instantiate (ExplosionObj,this.transform.position, this.transform.rotation);
				Instantiate (ExplosionForce,this.transform.position, this.transform.rotation);
				Destroy (this.gameObject);
			}
		}
	}
//	void OnTriggerEnter(Collider TheContact){
//		if (Detonate == true && TheContact.CompareTag("BuildingWall")) {
//			Detonate = false;
//			TheContact.gameObject.GetComponent<Rigidbody> ().AddExplosionForce (FirePower*10, this.transform.position, 1000f);
//			//print (TheContact);
//			Destroy (TheContact.gameObject);
//		}
//	}

	// Update is called once per frame
	void Update () {
		if (FuelLevel > 0) {
			FuelLevel -= 1;
		} else {
			Destroy (this.gameObject);
		}
	}
}
