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

public class CannonBullet : BaseBullet {

	[Header("Values")]
	public float speed = 6;
	public float upTime = 1f;

	Rigidbody2D rigidObject;

	Vector3 currentAngle;
	// Use this for initialization
	void Start () {
		rigidObject = GetComponent<Rigidbody2D>();	

		currentAngle = transform.rotation.eulerAngles;
	}

	float counter = 0;
	void FixedUpdate()
	{

		float tempSpeed = speed;
		if (counter < upTime)
		{
			counter += Time.deltaTime;
			if (counter >= upTime)
			{
				Vector3 angle = transform.rotation.eulerAngles;
				angle.z *= -1f;
				currentAngle = angle;
			}
		}
		else if (transform.rotation.eulerAngles != currentAngle)
		{
			transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(currentAngle), 
			Time.fixedDeltaTime * 360);
			tempSpeed*=1.5f;
		}



		Vector2 targetPosition = transform.position + ( transform.right * tempSpeed );
		transform.position = Vector2.MoveTowards(transform.position, targetPosition, Time.fixedDeltaTime * tempSpeed);

	}
	

}
