오늘 학습 키워드

최종 팀 프로젝트

오늘 학습 한 내용을 나만의 언어로 정리하기

스킬 중복 코드 리팩토링 하기

// SkillBase.cs
public virtual void Enter()  
{  
    useSuccessed = false;  
    if (!ConditionCheck())  
    {  
        if (controller.Move.rb.velocity.y != 0)  
        {  
            controller.ChangeState<FallState>();  
            return;  
        }  
        else  
        {  
            controller.ChangeState<IdleState>();  
            return;  
        }  
    }  
    useSuccessed = true;  
      
    controller.PlayerInputDisable();  
    controller.Move.rb.velocity = Vector2.zero;  
      
    controller.isLookLocked = true;  
    controller.Move.ForceLook(controller.transform.localScale.x < 0);  
    controller.Condition.isCharge = false;  
    controller.Condition.isSuperArmor = true;  
      
    animRunningTime = 0f;  
    lastUsedTime = Time.time;  
      
    controller.Animator.SetIntAniamtion(AnimatorHash.PlayerAnimation.AdditionalAttackID, skillId);  
    controller.Animator.SetTriggerAnimation(AnimatorHash.PlayerAnimation.AdditionalAttack);  
}
 
public abstract bool ConditionCheck(); 
 
  • 모든 스킬에서 중복되는 부분을 따로 SkillBase로 뺌
  • 그리고 스킬 각각이 ConditionCheck를 하도록 변경함

튜토리얼에서 2/3번째 몬스터 처음 때리면 에러 뜨던거

  • 자꾸 이펙트가 없다고 떴었는데, 그 이유를 추측해봄.

  • 일단 A라는 몬스터의 자식으로 이펙트를 생성함
  • 그럼 오브젝트 풀도 A의 자식인 VFX를 가리키고 있을 것임
  • 근데 A가 죽으면 A를 파괴함괴 동시에 자식들도 파괴될 것.
  • 오브젝트 풀에 있는 VFX는 여전히 A 자식에 있는 VFX를 참조하고 있음
  • 그래서 다른 몬스터인 B가 VFX를 재사용하려고 하면 이미 파괴한 오브젝트를 참조한다고 하여 에러를 띄우는 것으로 보임
  • 결과적으로 VFX를 누군가의 자식으로 포함하지 않도록 조절할 예정임.