Taking a Photo in Unity
Objective: Allow the user to take a photo on their device to use in our program.

One of the great things about Unity is we don’t have to “reinvent the wheel.” There are a lot of great — even free — assets we can import and use in our projects.

Native Camera for Android & iOS by yasirkula one of these great, free assets. Simply download it from the Asset Store and import it in your project. In the README file, you’ll find a link to the project’s Github.

This link will lead you to some example code snippets. The one we are interested in is the TakePicture method.

We’ll copy and paste this into our own script and modify it for our uses. The code will check to make sure our app has permission to access the user’s camera. If we do, we’ll store the picture as a Texture2D. We’ll assign that texture to our PhotoTaken object (which is of the RawImage type) and set it to active to display the picture. We’ll also store the path to where the image is located — we’ll need this for tomorrow’s article!
