Unity Community |

Hi there,
I'm slowly learning to program, but have many (probably silly) questions... I'm playing with the new Unity 3.5 webcam possibilities, and have the following code (mostly from the 'scripting reference'):
Code:
var webcamTexture : WebCamTexture; // Start web cam feed } // Do processing of data here. }
What I am trying to do here is... store the webcam data in an array (resolution 160x120), create a cube and give this the first color stored in the array. I can print the rgba data of this color, but don't know how to apply it to the cube. What I do on line 13 is obviously wrong... How do you do this?
Thanks!
add a texture to the cube and then use SetPixels32(data) and Apply on it.
Or simply apply webcamTexture to the cube directly instaed of trying to GET SET Apply![]()
Hi Dreamora,
Thanks for your reply! I'm not sure if I understand your feedback correctly... I'm not trying to apply the whole webcam-image to the cube, but only the rgba value of one 'pixel' of it. For that I need WebCamTexture.GetPixels32 right, not just WebCamTexture? And do I need a texture? I just want to apply the rgba data to material.color.
Maybe I should explain what I'm trying to achieve a bit better. I want to create a grid of 160x120 cubes, each cube displaying a color of the 160x120 webcam-feed. Understanding the problem mentioned above would be a first step to achieve this I figured...
Thanks again!
Got some help from a friend, in case other people want to know:
cube.transform.renderer.material.color = Color(data[0]);
should be:
cube.transform.renderer.material.color = data[0];
Works fine now!
If you're simply looking for the color of one pixel, it will be more efficient to use the WebCamTexture.GetPixel function. This will return the color of the specified pixel.
It was as simple as setting the texture and stop the device.
Thank you dreamora I was looking for that info.