Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Webcam texture Error

Discussion in 'Getting Started' started by vidit0210, May 29, 2016.

  1. vidit0210

    vidit0210

    Joined:
    Dec 30, 2015
    Posts:
    30
    Hello,

    I would like to use Full camera screen for my gameplay area.
    I am getting error in my webcam scripts.
    Here is my code
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. public class webcamC : MonoBehaviour {
    5.     GameObject cube;
    6.     WebCamTexture web;
    7.     // Use this for initialization
    8.     void Start () {
    9.         web = new WebCamTexture ();
    10.         cube.texture = web;
    11.         cube.material.MainTexture = web;
    12.         web.Play ();
    13.     }
    14.    
    15.     // Update is called once per frame
    16.     void Update () {
    17.    
    18.     }
    19. }
    20.  
     
  2. boolfone

    boolfone

    Joined:
    Oct 2, 2014
    Posts:
    289
    I tried this, and it works:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. public class webcamC : MonoBehaviour {
    5.  
    6.     public MeshRenderer cubeMR;
    7.     WebCamTexture web;
    8.  
    9.     // Use this for initialization
    10.     void Start () {
    11.         web = new WebCamTexture ();
    12.         cubeMR.material.mainTexture = web;
    13.         web.Play ();
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update () {
    18.  
    19.     }
    20. }
    21.  
    Screen Shot 2016-05-31 at 2.34.10 PM.png



    Be sure to drag your cube onto the cubeMR field.
     
  3. Shaba1

    Shaba1

    Joined:
    Jan 21, 2010
    Posts:
    63
    Nice simple compact code. Thanks I know you could do this with unity but I thought that the code would be very complicate.