Take Photo with Phone in Unity

Hal Brooks
3 min readJan 16, 2022

Objective: Take a photo using Android phone within the insurance app.

Take a photo with the app using Android camera.

The Take_Photo_Panel is constructed from several game objects as shown in the hierarchy below. It contains a grey overlay background, and other objects discussed later. The top and bottom borders are part of the Border_Panel, which is a modular panel and discussed in a previous article.

Take_Photo_Panel hierarchy.

The Take_Photo_Panel is controlled using TakePhotoPanel script component and requires several variables to store the photoImage, taken with the camera, as well as photoNotesText. In addition, the app needs to know the caseNumberText and the overviewContainer which controls the next panel or screen. The case number is retrieved from the UIManager’s active case and displayed at the top of the screen.

The Take_Photo_Panel, shown below, displays the Claim_Number_txt, and a Take_Photo_Button, that will be replaced by the photo image. There is also an Photo_Notes_InputField for photo note, and a Next_Button.

Take_Photo_Panel screen.

The camera is accessed using the TakePicture() script which is called from the Take_Photo_Button’s on click() events. This script is part of the Native Camera for Android & iOS.

Take_Photo_Button’s on click event.

Search the Unity asset store for the Native Camera for Android & iOS, which is free open source code. Open in Unity, download and install using the Package Manager, as shown below.

Package Manager

The TakePicture() method is derived from the Native Camera package but modified to store the image in the photoImage variable, as shown below. This image is then set to active, placing on top and hiding the Take_Photo_Button.

TakePicture() method in TakePhotoPanel.

Finally, the user will press the Next_Button which calls the ProcessInfo() method through the on click() event, similar to that shown for Take_Photo_Button.

ProcessInfo() method in TakePhotoPanel script.

--

--