General case, we can use these scripts below to display camera on the scene in the Unity3d.
WebCamTexture wc = new WebCamTexture ();
GameObject.Find (“/plane”).renderer.material.mainTexture = wc;
wc.Play ();
But sometimes we want to save camera to image, or realized video streaming. We can use WebcamTexture.GetPixels() and Texture2D.SetPixels(), but you must noticed returning width and height.
WebcamTexture construct can give requested width and height parameters. The issue occur when the parameters does not be supported by the chosen camera.
WebCamTexture wc = new WebCamTexture (160, 120);
wc.play();
Texture2D t = new Texture2D(wc.width, wc.height);
t.SetPixels(wc.GetPixels());
t.Apply();
On the Android, above scripts can worked fine, but on the iPhone 5S that texture t just showing blur. The reason is even iphone camera doesn’t suport requested width and height, the property width and height of WebCamTexture still returning requested values instead real values of camera.
So the simplest solution is using WebCamTexture() to replace WebCamTexture(160, 120). At last, I made an easy sample here. Please feel free to download and comment anything.
Reference :
Unity – Scripting API: WebCamTexture
http://docs.unity3d.com/ScriptReference/WebCamTexture.html
Another way is waiting few frames, then camera can get correct width and height.