왼쪽에 player를 클릭해놓고 움직이면 속도가 엄청빠름 아마 렉때문인듯
근데 player말고 다른오브젝트 클릭하고 움직이면 정상적임
player에 있는 콜라이더를 지우니까 정상속도로 다시 돌아오는데 콜라이더 하나때문에 이러는게 말이됨? 3d에서 콜라이더 엄청많이써도 렉 하나도 안걸렸는데 왜이러는거임???
public class PlayerCtrl : PlayerValueManager
{
Rigidbody2D rigidbody;
Animator animator;
Vector2 movement;
float MoveX;
float currentAttackDelay;
float currentComboTimer;
float MoveY;
int AttackCount = 1;
enum PlayerDirect{Left,Right};
public PlayerDirect playerDirect;
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();
}
void MoveCheck()
{
if(!animator.GetBool("isAttack"))
{
MoveX = Input.GetAxisRaw("Horizontal");
MoveY = Input.GetAxisRaw("Vertical");
rigidbody.velocity = new Vector2 (MoveX ,MoveY ).normalized *MoveSpeed * Time.deltaTime;
}
else
{
MoveX = 0;
MoveY = 0;
rigidbody.velocity = new Vector2(0,0);
}
}
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);
playerDirect = PlayerDirect.Left;
}
else if(MoveX > 0)
{
transform.localScale = new Vector2(3,3);
playerDirect = PlayerDirect.Right;
}
if(EndCheckAnimation("AttackMotion"))
animator.SetBool("isAttack" , false);
}
void AttackInputCheck()
{
if(Input.GetKeyDown(KeyCode.X) && currentAttackDelay < attackDelay && !isAttack )
{
if(AttackCount >= 5 )
{
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;
currentComboTimer -= Time.deltaTime;
if(currentComboTimer < 0)
AttackCount = 1;
}
IEnumerator Attack()
{
isAttack = true;
animator.SetBool("isAttack", true);
AttackMotionSelect();
yield return new WaitForSeconds(attackDelay);
AttackCount++;
currentAttackDelay = attackDelay;
isAttack = false;
}
void AttackMotionSelect()
{
if(AttackCount == 1)
{
animator.Play("Player_Attack1");
currentComboTimer = comboAttackTime;
}
else if(AttackCount == 2)
{
animator.Play("Player_Attack2");
currentComboTimer = comboAttackTime;
}
else if(AttackCount == 3)
{
animator.Play("Player_Attack3");
currentComboTimer = comboAttackTime;
}
else if(AttackCount == 4)
{
animator.Play("Player_Attack4");
}
}
}
자세한 설명, 스크립트가 필요해
스크립트 추가해서 올렸는데 이 문제가 스크립트때문은 아닌거가틈... 그냥 하이어라키에서 player를 클릭하고 움직이면 렉이걸림 근데 신기하게 그냥 암것도 클릭안해놓으면 렉이 안걸림 왜이러는지 모르겠음
에디터 상에서 '인스펙터'가 먹는 자원이 꽤나 되나봄. 다들 그래. 걱정하지 마.
인게임에서 전혀 문제없는 현상임.