using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public enum SIDE {Left, Mid, Right}
public class PlayerMove : MonoBehaviour
{
public SIDE m_side = SIDE.Mid;
float NewXpos = 0f;
[HideInInspector]
public bool SwipeLeft, SwipeRight;
public float XValue;
private CharacterController m_char;
private Animator m_animator;
private float x;
public float speeddodge;
void Start()
{
m_char = GetComponent<CharacterController>();
m_animator = GetComponent<Animator>();
}
void Update()
{
SwipeLeft = Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow);
SwipeRight = Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow);
if (SwipeLeft)
{
if(m_side == SIDE.Mid)
{
NewXpos = -XValue;
m_side = SIDE.Left;
m_animator.Play("Standing Dodge Left");
}else if(m_side == SIDE.Right)
{
NewXpos = 0;
m_side = SIDE.Mid;
m_animator.Play("Standing Dodge Left");
}
}
else if (SwipeRight)
{
if (m_side == SIDE.Mid)
{
NewXpos = XValue;
m_side = SIDE.Right;
m_animator.Play("Standing Dodge Right");
}
else if (m_side == SIDE.Left)
{
NewXpos = 0;
m_side = SIDE.Mid;
m_animator.Play("Standing Dodge Right");
}
}
x = Mathf.Lerp(x, NewXpos, Time.deltaTime * speeddodge );
m_char.Move((x -transform.position.x)*Vector3.right);
}
}