Using Device Camera – Unity3D (C#)

Using Device Camera – Unity3D (C#)

You can get image from device camera in your scene to use for VR, player portrait etc. It’s pretty easy and tricky. Actually there is no object for device camera. We use the image captured from camera as material and display it on an object -mostly on a basic plane.
Just imagine that there is a white projector screen (plane object) in scene. We reflect the image on it. All objects are stable, but changing the angle of the camera makes a real camera effect.
Lets start with scene objects. Create a plane(with tag “Plane”), directional light and camera.

Place them as seems below.

As you see in preview window, scene camera is faced to plane and we get a view from toward.

Create a new C# script and start coding. First, add game objects.

Then we need authorization to use the camera. Ask for it to device. Use “IEnumerator Start()” instead of default “void Start()”.

Initialization for texture and plane:

Now, get the image from device camera and reflect it on the plane.

Run it! It will display the image on the plane what camera captures. Full code is below.


©Coffee Break Codes – Using Device Camera – Unity3D (C#)

Leave a comment

Your email address will not be published. Required fields are marked *