In the Insurance application, it is now time for the user to upload a photo of the incident.
By clicking the “Press Here to Take Photo” button, the application will request the device to use the camera. I will be using a ready asset from the Unity Asset Store. By following the link here, you can download the “Native Camera for Android & IOS” for free. By following along the ReadMe file that is available once you import the asset to your project, you can easily make the required arrangements according to your device.
Thanks to Süleyman Yasir Kula, he shared the code as an open source and we can directly copy-paste the take picture or video functionality to our application without any struggle. You can find the github link in the Readme file.
By copying the method and changed it to be compatible with our code, the functionality will be working just fine.
As can be seen above, we have added a button to the image that tells “Press here to take photo”. Then, added the on click event of TakePictureButton to the button. Once the user clicks on the button, the camera will be activated on the device. Once the user confirms the photo, the raw image game object (which is set to inactive from the inspector by default) will become active — and as it is ranked under the image, it will look like it replaced the image component.
And that’s actually all :) I have tested it on the mobile and it works just fine.