public class PlayerCtrl : PlayerValueManager
{
Rigidbody2D rigidbody;
Animator animator;
float MoveX;
float currentAttackDelay;
float MoveY;
int AttackCount = 1;
bool isAttack = false;
// Start is called before the first frame update
void Start()
{
rigidbody = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
MoveCheck();
AnimCheck();
AttackInputCheck();
AttackDelayDecrease();
/* if(animator.GetCurrentAnimatorStateInfo(0).IsTag("AttackMotion"))
{
Debug.Log(animator.GetInteger("AttackCount") );
} */
Debug.Log(AttackCount);
}
void MoveCheck()
{
MoveX = Input.GetAxisRaw("Horizontal");
MoveY = Input.GetAxisRaw("Vertical");
rigidbody.velocity = new Vector2 (MoveX ,MoveY ) *MoveSpeed * Time.deltaTime;
}
void AnimCheck()
{
if(MoveX == 0 && MoveY == 0)
{
animator.SetBool("isRunning" , false);
}
else
{
animator.SetBool("isRunning", true);
}
if(MoveX < 0)
{
transform.localScale = new Vector2(-3,3);
}
else if(MoveX > 0)
{
transform.localScale = new Vector2(3,3);
}
if(AttackCount < 4)
{
animator.SetInteger("AttackCount" , AttackCount);
}
if(EndCheckAnimation("AttackMotion"))
animator.SetBool("isAttack" , false);
// AttackCount = animator.GetInteger("AttackCount");
}
void AttackInputCheck()
{
if(Input.GetKeyDown(KeyCode.X) && currentAttackDelay < attackDelay && !isAttack )
{
if(AttackCount >= 4 )
{
AttackCount = 1;
}
StartCoroutine(Attack());
}
}
bool EndCheckAnimation(string animationName)
{
return
animator.GetCurrentAnimatorStateInfo(0).IsTag(animationName) &&
animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 0.99f;
}
void AttackDelayDecrease()
{
currentAttackDelay -= Time.deltaTime;
}
IEnumerator Attack()
{
isAttack = true;
animator.SetBool("isAttack", true);
yield return new WaitForSeconds(attackDelay);
currentAttackDelay = attackDelay;
AttackCount++;
isAttack = false;
}
}
공격키 누를때마다 isAttack을 true로 바꾸고 재생을 99퍼까지하면 다시 false로바꿈(한번만 실행하기 위해서)
내가 원하는건 연속으로 4번누르면 공격모션 4개가 순차적으로 나가는거고 텀을두고 한번씩만 누르면 계속 첫번째 모션만 나오는거임
근데 어찌해야할지 감이 안잡힌다 첨부터 코드를 잘못짠거같음..
bool말고 trigger로 하면 끔켬 할 필요없엉 그리고 타이머같은거 해서 일정 시간내에 또 누르면 다음 모션 재생하면 되징
누를때마다 모션 변수 하나씩 오르게 하고 애니메이션은 항상 모션변수에 맞춰서 실행되게 만들어 그리고 키입력없이 시간이 지나거나 모션변수가 3을 넘으면 0으로 초기화 시키면되지