- Home /
Question by
montacerdk · Apr 19, 2018 at 04:01 PM ·
c#cameravuforiaaugmented reality
How to Switch/Change Front and back Vuforia AR Camera using a button?
Hey gus, I am developing an AR mobile app using Unity.
For that I have added a Vuforia AR Camera, it works fine with my Laptop cam, and it shows a 3D model on an image target.
My quastion is how can I switch between front cam and back cam on Android device using a simple button?
I have tried this code example to switch between the Laptop cam and an external webcam :
using UnityEngine;
using Vuforia;
public class SwitchCamera : MonoBehaviour
{
private bool cameraMode = false;
public void OnCameraChangeMode()
{
CameraDevice.CameraDirection currentDir = CameraDevice.Instance.GetCameraDirection();
if (!cameraMode)
{
RestartCamera(CameraDevice.CameraDirection.CAMERA_FRONT);
Debug.Log("Back Camera");
}
else
{
RestartCamera(CameraDevice.CameraDirection.CAMERA_BACK);
Debug.Log("Front Camera");
}
}
private void RestartCamera(CameraDevice.CameraDirection newDir)
{
CameraDevice.Instance.Stop();
CameraDevice.Instance.Deinit();
CameraDevice.Instance.Init(newDir);
CameraDevice.Instance.Start();
}
}
Comment