I used the code given by @Bart in the Stackoverflow question Can I take a photo in Unity using the device's camera? with some modification. But the result is coming out to be a completely black photo.
I would like to add that the script is attached to a cube which has a renderer. Also renderer was deprecated hence I had to use GetComponents() for the same.
You have to explicitly call WebCamTexture. Stop (); to stop it. The right place to do this is in the Disable() function.
We first start by deciding on the condition we use to change the camera. For now we'll use Input buttons 1, 2 and 3 to switch between cameras. We go into Project Settings -> Input Manager and add three new items to the list, which we'll label Switch1, Switch2, and Switch3. Each correspond to the button on the keyboard.
Whatever kind of experience you're developing, the Main Camera is always the primary stereo rendering component attached to your device's head-mounted display. It'll be easier to lay out your app if you imagine the starting position of the user as (X: 0, Y: 0, Z: 0).
I would think at the moment you take the shot, the rendering is not done since rendering happens late in the frame.
You should most likely use a coroutine and wait for the end of the frame
yield return new WaitForEndOfFrame();
or use the callback OnPostRender
from the camera that is rendering the process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With