c# - WebCamTexture 不显示在 Unity3D 中?

标签 c# camera unity3d

我正在尝试使用 WebCamTexture 在场景中显示网络摄像头输入。我创建了一个带有一些默认纹理的 Sprite 并将以下脚本附加到它:

public class CameraTexture : MonoBehaviour {

    void Start () {
        WebCamTexture webcamTexture = new WebCamTexture();
        renderer.material.mainTexture = webcamTexture;
        webcamTexture.Play();
    }
}

但是,当我运行场景(在 PC 上)时,不显示相机输入,只显示默认纹理。 这是我所知道的:

  • webcamTexture 不为空,正确找到设备
  • 摄像头设备工作正常
  • 其他应用没有挡住摄像头

为什么摄像头输入不显示?

最佳答案

我自己找到了解决方案。

webcamTexture 无法在 Sprite 上显示。 我不得不创建一个 GUITexture,然后我附加了相同的脚本并且一切正常。

关于c# - WebCamTexture 不显示在 Unity3D 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25339994/

相关文章:

c# - 将依赖项注入(inject)类库中的 AuthorizeAttribute

c# - ASP.NET C# 作用域问题

c# - 使用 JsonDerivedType 属性序列化和反序列化 .NET 7 中的多态对象

c# - 变换不会向上或向下旋转

c# - 从字符串 C# 中返回值的一部分

iOS/iPhone - 快速拍摄或连拍照片

c++ - 如何将 "camera"放入 OpenGL 的立方体中

opencv - 使用 opencv 的 aptina 相机问题

image - 在 Unity 3d 中切换设备相机

c# - Unity C#,脚本如何知道公共(public)变量(不是属性)何时更改