Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question The variable webcamTexture of xxxx has not been assigned.

Discussion in 'Scripting' started by Lxxiaodiao, Jan 7, 2023.

  1. Lxxiaodiao

    Lxxiaodiao

    Joined:
    Jan 7, 2023
    Posts:
    1
    Hey all,
    I encountered this error while running a project。

    UnassignedReferenceException: The variable webcamTexture of androidCam has not been assigned.
    You probably need to assign the webcamTexture variable of the androidCam script in the inspector.

    Here is my code(Excerpt from the webcam section)
    Code (CSharp):
    1. public WebCamTexture webcamTexture;
    2.  
    3. void Start ()
    4.     {
    5.  
    6.         imgData = new byte[640 * 480 * 4];      
    7.         Camera.main.depthTextureMode = epthTextureMode.Depth;
    8.  
    9.         data = new Color32[640 * 480*24];
    10.         tex = new Texture2D (640, 480, TextureFormat.RGBA32, false);
    11.         webcamTexture = new WebCamTexture(640, 480, 24);
    12.         webcamTexture.Play();
    13.        
    14.     }
    15. void Update ()
    16.     {
    17.         webcamTexture.GetPixels32(data);
    18.     }
    19.