- Home /
WebCamTexture producing tiling on Z10
I am using WebCamTexture to show video from my Z10's camera however I'm getting tiling, the cam display is being shown 4 times, however when I launch it on my Android tablet it works as it should with no tiling.
This is my script:
public class WebCameraScript : MonoBehaviour {
public GUITexture myCameraTexture;
private WebCamTexture webCameraTexture;
void Start () {
// Checks how many and which cameras are available on the device
for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++)
{
// We want the back camera
if (!WebCamTexture.devices[cameraIndex].isFrontFacing)
{
webCameraTexture = new WebCamTexture(cameraIndex, Screen.width, Screen.height);
// Here we flip the GuiTexture by applying a localScale transformation
// works only in Landscape mode
myCameraTexture.transform.localScale = new Vector3(-1,-1,2);
}
}
// Here we tell that the texture of coming from the camera should be applied
// to our GUITexture. As we have flipped it before the camera preview will have the
// correct orientation
myCameraTexture.texture = webCameraTexture;
// Starts the camera
webCameraTexture.Play();
}
public void ShowCamera()
{
myCameraTexture.guiTexture.enabled = true;
webCameraTexture.Play();
}
public void HideCamera()
{
myCameraTexture.guiTexture.enabled = false;
webCameraTexture.Stop();
}
void OnGUI()
{
// A button to demonstrate how to turn the camera on and off, in case you need it
if(GUI.Button(new Rect(0,0,100,100),"ON/OFF"))
{
if(webCameraTexture.isPlaying)
this.HideCamera();
else
this.ShowCamera();
}
}
}
I'm attaching it to a GUITexture and setting the insets and width/height to 0. Why is it working on my Android tablet but not on my Blackberry phone?
Answer by AlexThibodeau · Aug 19, 2013 at 03:35 PM
Hey there, we noticed a small issue in your code on this line:
webCameraTexture = new WebCamTexture(cameraIndex, Screen.width, Screen.height);
Currently this is using the following constructor for webcam:
WebCamTexture(requestedWidth: int, requestedHeight: int, requestedFPS: int)
I don't think this is the intended constructor that you want to be using. I would suggest doing the following:
webCameraTexture = new WebCamTexture(WebCamTexture.devices[cameraIndex].name, Screen.width, Screen.height);
Yeah, his answer wasn't visible when I was posting $$anonymous$$e. :-)