using UnityEngine;
using System.Collections;

public class PlayerArrow : MonoBehaviour {

	public float radius;    

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update ()
	{
        GameObject dealer = GameObject.Find("Dealer");

        setAngle(MathHelper.getVectorAngle((Vector2)(dealer.transform.position - PlayerMovement.instance.transform.position)));

		Vector3 pos = PlayerMovement.instance.transform.position + (Vector3)MathHelper.getVectorFromAngle (getAngle (), radius);
		pos.z = transform.position.z;
		transform.position = pos;

        if (((Vector2)(transform.position - dealer.transform.position)).magnitude < radius)
        {
            transform.position = new Vector3(-500f, 500f, transform.position.z);
        }
	
	}

	
	float getAngle()
	{
		return ((transform.eulerAngles.z* Mathf.PI / 180f));
	}
	
	void setAngle(float angle)
	{
		transform.rotation = Quaternion.EulerAngles (0f, 0f, angle);
	}
}
