using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;

namespace UnityStandardAssets._2D
{
    [RequireComponent(typeof (PlatformerCharacter2D))]
    public class Platformer2DUserControl : MonoBehaviour
    {
        private PlatformerCharacter2D m_Character;
        private bool m_Jump;


        private void Awake()
        {
            m_Character = GetComponent<PlatformerCharacter2D>();
        }


        private void Update()
        {
            if (!m_Jump)
            {
                // Read the jump input in Update so button presses aren't missed.
                m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
            }
        }


        private void FixedUpdate()
        {
            // Read the inputs.
            //bool crouch = Input.GetKey(KeyCode.LeftControl);
			//bool ataqueCorto = Input.GetKey(KeyCode.LeftShift);
			if (m_Character.enable) {
				float h = CrossPlatformInputManager.GetAxis ("Horizontal");
				float v = CrossPlatformInputManager.GetAxis ("Vertical");
				bool ataque = (h + v) == 0 ? Input.GetKey (KeyCode.LeftShift) : false;
				Vector2 vecVel = new Vector2 (h, v);
				// Pass all parameters to the character control script.
				m_Character.Move (vecVel, ataque/*,ataqueCorto*/);
				m_Jump = false;
			}
        }
    }
}
