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

"WebCamTexture.Play()" doesn't excute multiple times

Discussion in 'Scripting' started by macbread0625, Nov 25, 2019.

  1. macbread0625

    macbread0625

    Joined:
    Sep 11, 2019
    Posts:
    13
    I declared 2 WebCamTextures (e.g. webCamA, webCamB)

    and did Play(); at each textures.

    like

    webCamA.Play();
    webCamB.Play();

    and console shows me error below.
    aaaaa.PNG
    these error shows me no hint to solve problem.... I cant figure out what do I do next.

    with just 1 Play() function, all okay and work well.

    It seems like Unity can handle only 1 Play() funtion at a time.


    Is there any way to open 2 webcam stream at a time??
    not switch I'm making stereoscopic system...

    ps. this is my script attatched to 2 quads. (Cam number 0 is for Vive VR)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class EndoCam_Script : MonoBehaviour
    7. {
    8.     public enum CamIndex { Left, Right }
    9.     public CamIndex EndoCamSource;
    10.     public bool EndoCamON = false;
    11.  
    12.     void Update()
    13.     {
    14.         if (Input.GetKeyDown(KeyCode.Space)) EndoCamON = !EndoCamON;
    15.  
    16.         if (EndoCamON)
    17.         {
    18.             GetComponent<Renderer>().enabled = true;
    19.             //Debug.Log("EndoCam ON!");
    20.         }
    21.         else
    22.         {
    23.             GetComponent<Renderer>().enabled = false;
    24.             //Debug.Log("EndoCam OFF!");
    25.         }
    26.     }
    27.  
    28.     void Start()
    29.     {
    30.         WebCamDevice[] Connected_Camera_devices = WebCamTexture.devices;
    31.  
    32.         for (int i = 0; i < Connected_Camera_devices.Length; i++)
    33.             Debug.Log(Connected_Camera_devices[i].name + " // Camera number : " + i);
    34.  
    35.  
    36.         if (EndoCamSource == CamIndex.Left)
    37.         {
    38.             WebCamTexture endoCamTextureL = new WebCamTexture();
    39.             endoCamTextureL.deviceName = Connected_Camera_devices[1].name;
    40.             Debug.Log("Left Cam ON : " + endoCamTexture.deviceName + "\n");
    41.             GetComponent<Renderer>().material.mainTexture = endoCamTexture;
    42.             endoCamTextureL.Play();
    43.         }
    44.         else
    45.         {
    46.             WebCamTexture endoCamTextureR = new WebCamTexture();
    47.             endoCamTextureR.deviceName = Connected_Camera_devices[2].name;
    48.             Debug.Log("Right Cam ON : " + endoCamTexture.deviceName + "\n");
    49.             GetComponent<Renderer>().material.mainTexture = endoCamTexture;
    50.             endoCamTextureR.Play();
    51.         }
    52.     }
    53. }
    54.  
     
    Last edited: Nov 25, 2019
  2. macbread0625

    macbread0625

    Joined:
    Sep 11, 2019
    Posts:
    13
    Line 40, 41 - endoCamTexture -> endoCamTextureL
    Line 48, 49 - endoCamTexture -> endoCamTextureR

    I cant edit more, system detects editting is spam-like.. :p
     
  3. macbread0625

    macbread0625

    Joined:
    Sep 11, 2019
    Posts:
    13
    Solved.

    Using 2 cams on same usb hub is a problem.

    Unity seems like cant seperate devices on same hub.

    Dont use usb hub...