using UnityEngine;
using System.Collections;

public class AircraftController : MonoBehaviour {
	public VehicleChoice callBack;
	public GameObject Target;
	//private float rotationSpeed = 0.1F;
	private float speed = 0.0F;
	public float accelerationRate = 1.0F;
	public float maxspeed = 4.0F;
	private float distance = 0.0F;	// Use this for initialization
	//wektor początek w Aircraft koniec w Target
	private Vector3 TAVector = Vector3.zero;
	public bool started = false;
	public bool shooting = false;
	void Update () {
		if ( started ) {
			Flying ();
		} else {
		}
	}
	
	void Flying(){
		transform.LookAt (Target.transform);
		Target.transform.LookAt (transform);
		if ( shooting ) return; 
		TAVector = Target.transform.position -transform.position;
		distance = TAVector.magnitude;
		if (distance >= 3.0F) {
			speed = Mathf.MoveTowards(speed, maxspeed, Time.deltaTime * accelerationRate);
			rigidbody.velocity = transform.forward * speed;
		} else {
			speed = Mathf.MoveTowards(speed, 0.0F, Time.deltaTime * accelerationRate * 20.0F);
			rigidbody.velocity = transform.forward * speed;
		}
	}

	
	void OnMouseUpAsButton() {
		callBack.MouseUpAsButtonCallBack(this);
	}
}
