OVRHand 프리팹에서 검지와 엄지 Tip의 position 값을 받아와서 두 사이의 거리를 계산해 사용해야했다.
그런데 스크립트 상 OVRHand에서 index로 리스트처럼 그냥 접근하면 문제가 발생한다.
에러 중 헤드셋을 착용하기 전 null 문제가 뜨는 현상은 현재 손이 인식되지 않아서라고 생각하고, vr 헤드셋 쓴 후 실행했는데 여전히 해결되지 않았다.
그러던 중 해당 position을 사전에 초기화하고 사용하면 된다는 것을 발견하여 해결이 되었다!
public class GetBones : MonoBehaviour {
private OVRSkeleton skeleton;
private Transform indexTipTransform;
// Start is called before the first frame update
IEnumerator Start() {
skeleton = GetComponent<OVRSkeleton>();
while (skeleton.Bones.Count == 0)
{
yield return null;
}
foreach (var bone in skeleton.Bones)
{
if (bone.Id == OVRSkeleton.BoneId.Hand_IndexTip)
{
indexTipTransform = bone.Transform;
}
}
}
}
엄지도 동일한 방식으로 foreach문에서 BoneId.Hand_ThumbTip으로 접근했다.
이 부분을 해결하고자 OVRHand랑 OVRSkeleton 코드만 계속 쳐다봤는데 굉장히 간단하게 해결되었다.
(reference를 잘 찾아보자는 교훈을 오늘도 얻었다😣)