
오늘 학습 키워드
최종 팀 프로젝트, 모의 면접 대비 공부
오늘 학습 한 내용을 나만의 언어로 정리하기
최종 팀 프로젝트
죽었을 때 발동 되도록 이벤트버스 등록하기
// PlayerCondition.cs
private void Awake()
{
canStaminaRecovery = new Observable<bool>(EventBusKey.ChangeStaminaRecovery, false);
isDead = new Observable<bool>(EventBusKey.ChangePlayerDead, false);
controller = GetComponent<PlayerController>();
}
public void Die()
{
isDead.Value = true;
Debug.Log("[플레이어] 죽음!");
controller.ChangeState<DieState>();
controller.Inputs.Player.Disable();
}섬단에 저스트 섬단을 만들기
// SpecialAttackState.cs
public void LogicUpdate(PlayerController controller)
{
animRunningTime += Time.deltaTime;
if (animRunningTime >= justTiming)
{
controller.Attack.isStartJustAttack = false;
}
// AttackHitbox.cs
private void OnTriggerEnter2D(Collider2D other)
{
if (controller.Attack.isStartParry)
{
if (other.TryGetComponent(out ICountable countable))
{
Debug.Log("[플레이어] 플레이어 패링 시도");
if (countable.CounterAttacked())
{
controller.Attack.successParry = true;
Debug.Log("[플레이어] 플레이어 패링 성공");
}
}
}
if (controller.Attack.isStartJustAttack)
{
if (other.TryGetComponent(out ICountable countable))
{
Debug.Log("[플레이어] 플레이어 저스트 어택!");
if (countable.CounterAttacked())
{
controller.Attack.successJustAttack = true;
controller.Attack.JustSpecialAttack();
}
}
}
카메라 흔드는 이펙트 주기
if (other.TryGetComponent<IDamagable>(out var damagable))
// && other.gameObject.layer == LayerMask.NameToLayer("Monster"))
{
ShakeCameraUsingState();
damagable?.TakeDamage(Damage);
Debug.Log($"[플레이어] 플레이어가 몬스터에게 {Damage} 만큼 데미지 줌");
}아래 점프 하면 플랫폼에서 내려갈 수 있도록 구현
if (input.y < 0 && controller.Inputs.Player.Jump.triggered && controller.Move.isGrounded )
{
Debug.Log("[플레이어] 아래 점프 입력됨");
RaycastHit2D hit =
Physics2D.Raycast((Vector2)controller.transform.position, Vector2.down, controller.halfPlayerHeight + 1f, LayerMask.GetMask("Ground"));
if (hit.collider != null)
{
if (hit.collider.CompareTag("Platform"))
{
Debug.Log("[플레이어] 아래 점프 입력된 후 플랫폼 발견됨");
await TurnOffPlatformCollider(hit.collider);
controller.ChangeState<FallState>();
}
}
}모의 면접 대비 공부
-
Q1. 가비지 컬렉터란 무엇인가요?
-
A1. 가비지 컬렉터는 힙에서 더 이상 사용하지 않는 메모리를 정리해주는 프로세스입니다. 어떤 힙 메모리 부분이 사용되지 않고 있는지 확인하기 위해, 가비지 컬렉터는 모든 액티브 레퍼런스 변수를 검색하고 이 변수가 참조하는 메모리 블록을 살아있다고 표시합니다. 모든 검색이 끝나면 살아있는 블록 사이 공간이 비어있는 것으로 간주하고 이후에 할당할 수 있도록 표시합니다.
-
Q2. 제네릭이란 무엇인가요?
-
A2. 제네릭은 데이터의 타입을 일반화해서 코드의 재사용성과 유연성을 높이는 기능입니다. 코드를 짤 때 타입을 지정하는게 아니고 나중에 실제 타입이 결정되도록 합니다.
-
Q3. MonoBehaviour 클래스의 주요 메서드와 그 기능에 대해 설명해주세요.
- MonoBehaviour 클래스에서 Start와 Awake의 차이점은 무엇이며, 이를 적절히 사용하는 방법에 대해 설명해주세요.
-
A3. MonoBehaviour 클래스에서 주요 메소드로는 생명주기 메소드 들이 있습니다. Awake, OnEnable, Start 순으로 처음에 실행되고, 그 뒤로 주기적으로 Update, LateUpdate가 실행됩니다. FixedUpdate의 경우에는 고정된 시간 간격에 따라 호출됩니다. 그리고 파괴되기 전에는 OnDisable, OnDestroy가 불립니다. Start와 Awake의 차이점으로는 Awake는 인스턴스가 처음 로드될 때 호출된다는 점, Start는 첫 프레임 업데이트가 실행되기 전에 한 번 호출된다는 점이 있습니다. 모든 오브젝트의 Awake가 끝난 후에 Start가 불리기 때문에, 다른 클래스에 접근해야 할 때에는 Start에서 하는게 좋습니다.
-
Q4. 코루틴과 멀티쓰레딩은 어떤 차이가 있는지 설명해주세요.
-
A4. 코루틴은 여전히 싱글 쓰레드로 돌아가고 있다는 점에서 멀티 쓰레딩과 다릅니다. 코루틴은 메인 스레드 안에서 쪼개가면서 시간을 점유합니다. 그러나 멀티 쓰레딩은 실제로 멀티 코어를 사용해서 병렬 처리를 한다는 점에서 차이가 있습니다.
학습하며 겪었던 문제점 & 에러
문제 1
- 문제&에러에 대한 정의
높은 곳에서 다운어택을 하면 바닥을 뚫는 현상이 있었음
- 해결 방법

- Rigidbody의 Collision Detection을 discrete (이산) 말고 continuous (연속) 으로 바꾸면 됨
문제 2
- 문제&에러에 대한 정의
플레이어가 플랫폼 위에서 아래키 + 점프키를 누르면 플랫폼을 무시하고 아래로 떨어지도록 하려고 했으나, 그게 안됨.
- 내가 한 시도
if (input.y < 0 && controller.Inputs.Player.Jump.triggered && controller.Move.isGrounded )
{
Debug.Log("[플레이어] 아래 점프 입력됨");
RaycastHit2D hit =
Physics2D.Raycast((Vector2)controller.transform.position, Vector2.down, controller.halfPlayerHeight + 1f, LayerMask.NameToLayer("Ground"));
if (hit.collider != null)
{
if (hit.collider.CompareTag("Platform"))
{
Debug.Log("[플레이어] 아래 점프 입력된 후 플랫폼 발견됨");
await TurnOffPlatformCollider(hit.collider);
controller.ChangeState<FallState>();
}
}
}- 해결 방법
NameToLayer로 레이어를 찾으면 그냥 숫자가 나와버리기 때문에 비트마스크 연산이 안됨. 따라서 이때는 GetMask 로 해야함.
if (input.y < 0 && controller.Inputs.Player.Jump.triggered && controller.Move.isGrounded )
{
Debug.Log("[플레이어] 아래 점프 입력됨");
RaycastHit2D hit =
Physics2D.Raycast((Vector2)controller.transform.position, Vector2.down, controller.halfPlayerHeight + 1f, LayerMask.GetMask("Ground"));
if (hit.collider != null)
{
if (hit.collider.CompareTag("Platform"))
{
Debug.Log("[플레이어] 아래 점프 입력된 후 플랫폼 발견됨");
await TurnOffPlatformCollider(hit.collider);
controller.ChangeState<FallState>();
}
}
}- 새롭게 알게 된 점
레이캐스팅 할 때에는 레이어 “마스크”로 해야됨