본문 바로가기
개발더미

[개발더미][Unity] 타점에 콜라이더 생성, Physic.OverlabSphere()

by 스테디코디스트 2023. 7. 25.
반응형
protected override void OnAttack()
    {
        // 공격 발생시 동작
        print("atk");

        // 타점 주변의 콜라이더 중 Monster 레이어를 가진 콜라이더만 가져옴
        // 문제 발생 : 3번째 공격부터 콜라이더 인식을 못함ㅋㅋ
        // 해결 -> rigidbody의 isKinematic을 체크하여 해결!
        Collider[] monsterColiders = Physics.OverlapSphere(attackPoint.position, 1, attackLayer);

        foreach (Collider col in monsterColiders)
        {
            print(col.gameObject.name + "  attack");

            if (col.GetComponent<Monster>() == null) continue;

            // 판정안에 들어온 몬스터
            Monster curMonster = col.GetComponent<Monster>();

            curMonster.myStatus.HP -= 10;
        }
    }