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 e-mail address will not be published. Required fields are marked *

3 thoughts on “Using Device Camera – Unity3D (C#)

  • minecraft

    I blog often and I genuinely thank you for your content.
    Your article has really peaked my interest. I will book mark your
    site and keep checking for new details about once per week.
    I opted in for your Feed as well.

  • minecraft

    Very nice post. I just stumbled upon your blog and wished to
    mention that I’ve truly loved surfing around your blog posts.
    After all I will be subscribing in your rss feed and I am hoping you write again very