Camera plugin for Unity
Objective: Add a camera plugin for Unity that will allow for photos to be taken by the user
In some apps they allow the user to take pictures and videos and use them in the app. I needed to be able to do this in an app I’m making as a side project and I came across a free plugin on the asset store that allows for easy installation that allows the user to take a photo in your app.
You can find the plugin here. I am going to run through how to use the plugin inside of Unity and for Android (sorry iOS users).
First add the plugin to your assets and find it in the package manager inside your project. Then download and install as usual. For android users the once the plugin is installed that is the only setup that you have to do (at the moment of writing).
There is great documentation for how to set up the plugin for iOS users.
You can obviously open this file up and read in a format that suits you. Once open, if you got to the GitHub link you will be able to copy and paste the example shown. Scroll down the page and you will see some example code for taking a photo and video.
For my app I just wanted the user to be able to take a photo, so I copied the TakePicture method code and pasted it into my script. I didn’t need to assign a temp quad like in the example so I deleted that part of the code and replaced it with what I wanted to happen. Which is to store the photo taken in a rawImage texture, so that I can use it later on.
I did run into an issue when copying the code over, because the plugins scripts were under another namespace the current script didn’t know about the NativeCamera script. So, my solution was to move the entire native Camera folder from plugins into my scripts folder.
Do this made sure that the current TakePhoto Script knows about the NativeCamera scripts and allowed me to access them. And that is it. Well for android users, as I said above iOS users have more to do to get it to work but it is well worth it as it saves hours of work to create your own solution that might not work as well as this plugin.
If you found this helpful, don’t forget to clap and follow for more articles on game development in Unity.