Implementing Native Camera Plugin for Android!

addam davis
3 min readMar 3, 2022

Objective: Create functionality for camera!

In the last tutorial we imported the Native Camera plugin into our project. Now I’ll show you how to implement this plugin to access the camera on your phone. Open the read me, and inside is a link to the scripting API. Follow that URL.

Towards the bottom of the scripting API they provide us with an example code for taking photos and recording videos. We are simply going to copy the photo method and customize it to fit our needs.

I’m going to paste this code into the take photo panel script.

There is a section of code that is labeled by a comment “assigns texture to temporary quad and destroy it after 5 seconds.” We don’t want to destroy it so we are going to select that section and delete it.

Replace this code with setting the RawImage to the photo texture and Activate the RawImage gameObject.

We want to call this method when a button is pressed. Make a method to call this take picture method.

The 512 is the size of the photo, set to whatever size you need.

In Unity we want to select the Image thumbnail and add a button component.

Create an On Click Event to call the TakePictureButton method.

To test your photo abilities, you will need to build and run on your device. Don’t be afraid to experiment with your photo sizes and I’ll see you in the next tutorial!

--

--