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

public class RocketBullet : BaseBullet {

	[Header("Values")]
	public float speed = 12;
	public Vector2 targetPosition;

	public Transform particleObject;


	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		Vector2 targetPosition = transform.position + ( transform.right * speed );
		transform.position = Vector2.MoveTowards(transform.position, targetPosition, Time.fixedDeltaTime * speed);
	}

	void OnTriggerEnter2D(Collider2D other)
	{
		if (other.name == "top")
		{
			transform.rotation = Quaternion.Euler(0,0,-90);
			Vector2 currentPosition = transform.position;
			currentPosition.x = targetPosition.x;
			transform.position = currentPosition;
		}
		else if (gameObject.activeSelf == true && other.gameObject != owner)
		{
			particleObject.parent = null;
			Destroy(particleObject.gameObject, 2);
			gameObject.SetActive(false);
			Destroy(gameObject);
		}
	}
}
