我使用的是WebCamTexture和我在Start
方法來啓動它,然後我跑的另一種方法。我使用GetPixels()
獲得像素,但是,它們都是(0, 0, 0)
。是否有任何修復或我可以等待的方式(Unity似乎使用while
循環和WaitForSeconds
)崩潰。這是我目前的入門方法:WebCamTexture想出在第一,第二或全0二
void Start() {
rawImage = gameObject.GetComponent<RawImage>();
rawImageRect = rawImage.GetComponent<RectTransform>();
webcamTexture = new WebCamTexture();
rawImage.texture = webcamTexture;
rawImage.material.mainTexture = webcamTexture;
webcamTexture.Play();
Method();
loadingTextObject.SetActive (false);
gameObject.SetActive (true);
}
void Method(){
print (webcamTexture.GetPixels [0]);
}
而這個打印每次(0, 0, 0)
顏色。
嗨迪倫。這是Unity和網絡攝像機的一個衆所周知的問題。你實際上需要做的是等到***報告一個合理的大小***。在實踐中,你跳過框架,直到你的WebCam.width大於100.它在這裏完全解釋http://answers.unity3d.com/questions/773464/webcamtexture-correct-resolution-and-ratio.html – Fattie
BTW大多數人只是使用NatCam https://www.assetstore.unity3d.com/en/#!/content/52154這些天。 Unity的攝像頭軟件是廢話。這是他們「還沒有到」的事情之一。準備花上幾個星期與攝像頭一起工作。 – Fattie
噢好吧我已經在別的地方做這個了。希望這會起作用。 –