前提・実現したいこと
以下URLを参考にWebカメラの撮影画像をUnityで表示しようとしております。
http://www.urablog.xyz/entry/2017/07/06/225444
発生している問題・エラーメッセージ
ですが、以下のエラーメッセージが表示され、画像の取得に至りません。
NullReferenceException: Object reference not set to an instance of an object Testcamera+<Start>c__Iterator0.MoveNext () (at Assets/TestScenes/WebCam/Testcamera.cs:37)
該当のソースコード
以下がソースコードになります。
using UnityEngine; using UnityEngine.UI; using System.Collections; public class Testcamera : MonoBehaviour { [SerializeField] private int m_width = 1920; [SerializeField] private int m_height = 1080; [SerializeField] private RawImage m_displayUI = null; private WebCamTexture m_webCamTexture = null; private IEnumerator Start() { if( WebCamTexture.devices.Length == 0 ) { Debug.LogFormat( "カメラのデバイスが無い様だ。" ); yield break; } yield return Application.RequestUserAuthorization( UserAuthorization.WebCam ); if( !Application.HasUserAuthorization( UserAuthorization.WebCam ) ) { Debug.LogFormat( "カメラを使うことが許可されていないようだ。" ); yield break; } // とりあえず最初に取得されたデバイスを使ってテクスチャを作りますよ。 WebCamDevice userCameraDevice = WebCamTexture.devices[ 0 ]; m_webCamTexture = new WebCamTexture( userCameraDevice.name, m_width, m_height ); m_displayUI.texture = m_webCamTexture; // さあ、撮影開始だ! m_webCamTexture.Play(); } }
試したこと
Webカメラの動作確認(Logicoolのアプリケーションからは動画取得可能)
当該ノートPCの内臓カメラのドライバ無効化(device[0]の割り当てを疑って)
補足情報(FW/ツールのバージョンなど)
Unity 2017.1.0f3
webカメラ Logicool c920r
よろしくお願いいたします<(_ _)>

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/24 06:38