Skip to main content

Posts

Showing posts from June, 2016

How to use webcam in unity new UI

Hello! guys...

welcome to another post on UI :)

so in my last project there was a requirement of creating a selfie screen in unity, so i used new UI to create it.

There was some challenges but as always unity community was very helpful, that is the reason i thought of sharing my experience here in this blog.

My setup in unity was really simple, I used rawImage and assigned webcamTexture to its  texture   property, and that's it, once you call webcamTexture.Play(); you will get the realtime feed from camera in your rawImage.

here is an image showing my setup.



you can see that, my rawImage width is larger than its height, thats because my webcamTexture width was larger than its height, so if i keep it in square shape, my image was getting stretched, so thats why i kept it like that.

But to tackle this problem i am cropping my final texture to a square shape, based on smaller width /height, which gives me a perfect square shape image without any stretching.

here is a sample of my f…