using UnityEngine;
using System.Collections;

public class Cicada : MonoBehaviour {
	public float m_speed = 1;
	public float m_Xscale = 1;
	public float m_YScale = 1;
	private Vector3 m_Pivot;
	private Vector3 m_PivotOffet;
	private float m_Phase;
	private bool m_Invert=false;
	private float m_2PI= Mathf.PI*2;


	public float yOriginal;
	public bool GoUp;
	// Use this for initialization
	void Start () {
	
		m_Pivot = transform.position;
	}
	
	// Update is called once per frame
	void Update () {
		m_PivotOffet = Vector3.up * 2 * m_YScale;
		m_Phase += m_speed * Time.deltaTime;

		if (m_Phase > m_2PI) {
			m_Invert = !m_Invert;
			m_Phase -= m_2PI;
		}
		if (m_Phase < 0)
			m_Phase += m_2PI;

		transform.position	= m_Pivot + (m_Invert ? m_PivotOffet : Vector3.zero);
		transform.position= new Vector2( (Mathf.Sin (m_Phase) * m_Xscale) + transform.position.x, 
			transform.position.y + (Mathf.Cos (m_Phase) * (m_Invert ? -1 : 1) * m_YScale));
			
	}
}
