using UnityEngine;
using System.Collections;

public class RotateAroundShip : MonoBehaviour 
{
	public float Radius = 4.5f;
	public float Angle;
	public float RotationSpeed = 3f;

	public Vector3 center;

	public bool RotateThis = true;
	public Vector3 ThisRotationSpeed = new Vector3(0,0,6f);
	
	Transform thisTransform;

	public GameObject ShipBase;
	public GameObject Model;

	void Awake() 
	{
		thisTransform = transform;
		Angle = Random.Range (0,360);

		if (!ShipBase)
			ShipBase = GameObject.Find ("ShipBase");
	}
	
	void Update () 
	{
		Angle += RotationSpeed * Time.deltaTime;
		Vector2 newPos = new Vector2();
		newPos.x = center.x + Radius * Mathf.Cos(Angle);
		newPos.y = center.y + Radius * Mathf.Sin(Angle);

		thisTransform.position = newPos;

		if (RotateThis && ShipBase != null) 
		{
			//iTween.LookTo(gameObject, iTween.Hash("looktarget",new Vector3(0,0,0), "time",0.05f));

			thisTransform.Rotate(ThisRotationSpeed);
		}
	}
}
