- Home /
Webcamtexture not showing on a SpriteRenderer
I've been trying to get a WebCamTexture onto a sprite-renderer, and I've looked through other questions, but none of them have solved the problem I've been having.
The material, once applied to the sprite-renderer, just shows up as a purple sheet. I am attempting to apply the WebCamTexture to a white sprite as a background.
public GameObject testObj;
private WebCamTexture m_texture = null;
void Start ()
{
Application.RequestUserAuthorization (UserAuthorization.WebCam);
m_texture = new WebCamTexture ("Remote Back Camera");
m_texture.Play ();
gameObject.GetComponent<SpriteRenderer>().material.mainTexture = m_texture;
gameObject.GetComponent<SpriteRenderer> ().material.renderQueue = 3001;
}
private void Update ()
{
if (null != m_texture &&
m_texture.didUpdateThisFrame) {
gameObject.GetComponent<SpriteRenderer>().material.SetTexture = m_texture;
}
}
The camera is working, and I can get it working with a GUITexture, but I need it to be behind several sprites, and in front of others, so a Sprite-Renderer seems like the best way to do that.
Any help would be greatly appreciated, thanks!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612091539im_/https://answers.unity.com/themes/thub/images/avi.jpg)