Search code examples
c#cameraunity-game-engine

WebCamTexture not displayed in Unity3D?


I'm trying to display web camera input on scene, using WebCamTexture. I've created a Sprite with some default texture and attached following script to it:

public class CameraTexture : MonoBehaviour {

    void Start () {
        WebCamTexture webcamTexture = new WebCamTexture();
        renderer.material.mainTexture = webcamTexture;
        webcamTexture.Play();
    }
}

But, when I run the scene (on PC), the camera input isn't displayed, only the default texture. Here is what I know:

  • webcamTexture isn't null, the device is properly found
  • camera device works properly
  • other apps aren't blocking the camera

Why is the camera input not displayed?


Solution

  • I've found a solution myself.

    The webcamTexture cannot be displayed on Sprite. I had to create a GUITexture instead, then I attached the same script and everything worked fine.