참고
- 이미지 타겟팅으로 오브젝트 띄우기 From Image
- OnTargetStatusChanged로 타겟 상태 관리하기
AR 카메라가 이미지를 인식하거나 놓치는 것은 OnTargetStatusChanged를 이용해서 추적하였다.
이미지 타겟 오브젝트에서 제공하는 OnTargetFound와 OnTargetLost는
이미지가 인식된 후 생성된 오브젝트를 추적해 이벤트를 발생할 수 있다.
먼저 빈 오브젝트를 만든 후, TestCode.cs를 추가하자.
TestCode.cs는 다음과 같다.
LogWarning과 LogError로 로그를 구분하였다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestCode : MonoBehaviour
{
public void Found()
{
Debug.LogWarning("Target Found");
}
public void Lost()
{
Debug.LogError("Target Lost");
}
}
이미지 타겟에서 이벤트에 TestCode의 Found와 Lost 메서드를 추가하자.
이제 게임을 실행해보자.
이미지를 가리더라도 오브젝트가 남아있으면 Target Lost 로그가 남지 않는다.
카메라에서 오브젝트가 완전히 사라진 경우 OnTargetLost가 실행되는 것을 알 수 있다.
Unity Plus:
Easy 2D, 3D, VR, & AR software for cross-platform development of games and mobile apps. - Unity Store
Have a 2D, 3D, VR, or AR project that needs cross-platform functionality? We can help. Take a look at the easy-to-use Unity Plus real-time dev platform!
store.unity.com
Unity Pro:
Unity Pro
The complete solutions for professionals to create and operate.
unity.com
Unity 프리미엄 학습:
Unity Learn
Advance your Unity skills with live sessions and over 750 hours of on-demand learning content designed for creators at every skill level.
unity.com
댓글