Sitemap

Implementing Native Camera Plugin for Android!

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.

Press enter or click to view image in full size

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.

Press enter or click to view image in full size

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

Press enter or click to view image in full size

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.

Press enter or click to view image in full size

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

Press enter or click to view image in full size

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

Press enter or click to view image in full size
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.

Press enter or click to view image in full size

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!

--

--

No responses yet