I’m working on an AR project, and I’m trying to get a feed from the Android’s camera to display as a constant background image. I followed the tutorial listed in this post to get a normal GUI Texture to be constantly displayed, but I’m having trouble applying the webcam texture to the GUI Texture.
This is the JavaScript I’m using (based on another example):
var cameraOutput : GUITexture;
private var webcamTexture : WebCamTexture;
private var devices : WebCamDevice[];
function Start () {
devices = WebCamTexture.devices;
webcamTexture = WebCamTexture();
if(devices.length > 0){
webcamTexture.deviceName = devices[0].name;
webcamTexture.requestedWidth = Screen.width;
webcamTexture.requestedHeight = Screen.height;
var width = webcamTexture.requestedWidth;
var height = webcamTexture.requestedHeight;
var centerX = (width/2) *-1;
var centerY = (height/2) * -1;
cameraOutput.pixelInset = Rect(centerX, centerY, width, height);
cameraOutput.texture = webcamTexture;
webcamTexture.Play();
}
}
function OnGUI () {
if (WebCamDevice == null){
GUI.Label(Rect(10,10,65,25),"NO ACTIVE CAMERA");
}
}
I applied this script to the GUI Texture object I created, and all I see is the standard blue background and the reference texture I added in the inspector window (a tree). I’m pretty new to Unity so it’s probably just a simple mistake, I guess I just need an extra set of eyes.
Something’s working right because I’m not seeing “NO ACTIVE CAMERA.”
Like I said, an extra set of eyes on this would be much appreciated!