using UnityEngine;
using System.Collections;

public class PlayerChangeShapeScript : MonoBehaviour 
{
	public PlayerLearnShapeScript learnShape;

	public SpriteRenderer mySpriteRenderer;
	private Sprite defaultSprite;

	private bool axisPressed = false;

	// Use this for initialization
	void Start () 
	{
		defaultSprite = mySpriteRenderer.sprite;
	}
	
	// Update is called once per frame
	void Update () 
	{
		// We have learned a shape
		if (learnShape.currentShape != null)
		{
			// We hit the change button
			if (Input.GetAxis("Change") != 0 && !axisPressed)
			{
				if (PlayerStateManager.instance.currentPlayerState == Enums.PlayerState.Default)
				{
					PlayerStateManager.instance.currentPlayerState = Enums.PlayerState.Morphing;
					mySpriteRenderer.sprite = learnShape.currentSprite;
				}
				else if (PlayerStateManager.instance.currentPlayerState == Enums.PlayerState.Morphing)
				{
					mySpriteRenderer.sprite = defaultSprite;
					PlayerStateManager.instance.currentPlayerState = Enums.PlayerState.Default;
				}

				axisPressed = true;
			}
			if (Input.GetAxis("Change") == 0)
			{
				axisPressed = false;
			}
		}
	}
}
