Andrei Schneider
Andrei Schneider

Reputation: 3563

Is it possible to set video from device camera as background in Unity3d?

I'm implementing an augmented reality prototype. But I have not figured out how to set video as background. There is a WebCamTexture class which can be set as a texture for GUITexture. But in this case other 3d objects are not visible.

Upvotes: 1

Views: 3105

Answers (3)

chobits
chobits

Reputation: 1

Attach following code to your main camera and you are done

public class webcam_example : MonoBehaviour
{
    WebCamTexture webcamTexture;
    bool webcam_ok = false;
    void Start()
    {
        WebCamDevice[] webCams = WebCamTexture.devices;
        if (webCams.Length > 0) {
           webcamTexture = new WebCamTexture();
           webcamTexture.Play();
           webcam_ok = true;
        }
    }

    void OnPreRender()
    {
        if (webcam_ok)
        {
            Graphics.Blit(webcamTexture, (RenderTexture)null);
        }
    }
}

Upvotes: 0

flyzhao
flyzhao

Reputation: 348

create 2 cameras, one set to view all the 3d object , the other with the GUITexture.

Upvotes: 0

Sumeet Jindal
Sumeet Jindal

Reputation: 902

  1. Create a plane
  2. Attach it to Camera Node
  3. GameObject->Align View to Selected
  4. Translate the plane to 900
  5. Scale the plane to fit the screen.

Upvotes: 1

Related Questions