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 *

13 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

  • minecraft

    Greetings! I’ve been reading your weblog for a while now
    and finally got the courage to go ahead and give you a shout out from Houston Texas!
    Just wanted to mention keep up the excellent work!

  • minecraft

    Hey there! I know this is kinda off topic however , I’d figured I’d ask.
    Would you be interested in trading links or maybe guest writing a blog article or vice-versa?
    My website goes over a lot of the same subjects as
    yours and I think we could greatly benefit from each other.

    If you’re interested feel free to shoot me an e-mail.
    I look forward to hearing from you! Superb blog by the way!

  • gamefly

    Have you ever thought about writing an e-book
    or guest authoring on other websites? I have a blog based on the same ideas you discuss and would really
    like to have you share some stories/information. I know my visitors
    would value your work. If you are even remotely interested,
    feel free to shoot me an email.

  • gamefly

    Thanks for another informative website. Where else could I am getting that kind of information written in such an ideal way?

    I’ve a venture that I am simply now operating on, and I’ve
    been on the look out for such info.

  • gamefly free trial

    Hi would you mind letting me know which web host you’re utilizing?
    I’ve loaded your blog in 3 different browsers and I must say this blog loads a lot faster then most.

    Can you suggest a good internet hosting provider at a honest price?
    Thanks, I appreciate it!