Hi
I am creating an application using an AR camera.
Currently, I would like to switch between world and user cameras using a button on the app. To achieve this, I wrote the code below to change the requestedFacingDirection property in ARCameraManager.
However, when I actually ran the code, I was able to confirm that the CameraSwitch() function was called by button operation, but the camera was always displaying the image from the world camera and the image did not switch.
Is there an error in using the requestedFacingDirection property? (If there is any other way to achieve this function, please let me know)
Code:
using UniRx;
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
public class CameraChangeView : MonoBehaviour
{
//----------------------------------------------------------------------------------//
// Member
//----------------------------------------------------------------------------------//
[SerializeField] private Button CameraChangeButton;
[SerializeField] private ARCameraManager arCamera;
public event Action OnCameraChangeButtonClick;
//----------------------------------------------------------------------------------//
// Event
//----------------------------------------------------------------------------------//
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
CameraChangeButton.onClick.AsObservable().Subscribe( _ => OnButtonClick());
}
// Update is called once per frame
void Update()
{
}
public void CameraSwitch(int cameraNum)
{
if(cameraNum == 0)
{
arCamera.requestedFacingDirection = CameraFacingDirection.User;
}
else
{
arCamera.requestedFacingDirection = CameraFacingDirection.World;
}
}
private void OnButtonClick()
{
OnCameraChangeButtonClick?.Invoke();
}
}