개발/공부
[유니티] 충돌 검사 짤팁
ssong_dev
2022. 6. 14. 13:12
게시글 따로 저장하기 애매한 짤팁들은 이 게시글에 조금씩 추가 예정...
충돌 검사 시 tag 대신 GetComponent 검사 해 주면 좋다.
여러 종류의 태그를 주르륵 추가하는 것 보다 other.GetComponent<클래스명>() != null 로 검사하면
해당 클래스 가지고 있는 요소들 한꺼번에 검사하기 좋다.
아래는 AR 공던지기 충돌 검사 코드
private void OnTriggerEnter(Collider other)
{
if(other.GetComponent<BallUnit>() != null)
{
sheepBottle.inTrigger = true;
sheepBottle.rigidbody.isKinematic = false;
}
}