how can i measure the light level entering my webcam
Hi, im a semi novice coder and this is my first time asking a question because i cant find the answer anywhere.
im making an android game that uses the light entering the camera to effect some gameplay. I need to make a bar that goes up or down to represent the level of light entering my device camera , im using a webcam texture, and thought that i could use the color date it produces, but i dont know how to get that data, or how to use it to change the bar's size. my script looks like this:
{ private bool camAvailable; private WebCamTexture frontCam; private Texture defaultBackground; public Color32[] camLight; public RawImage background; public AspectRatioFitter fit;
private void Start()
{
defaultBackground = background.texture;
WebCamDevice[] devices = WebCamTexture.devices;
if (devices.Length == 0)
{
Debug.Log("no camera detected");
camAvailable = false;
return;
}
for (int i = 0; i < devices.Length; i++)
{
if (devices[i].isFrontFacing)
{
frontCam = new WebCamTexture(devices[i].name, Screen.width, Screen.height);
}
}
if (frontCam == null)
{
Debug.Log("unable to find front camera");
return;
}
frontCam.Play();
background.texture = frontCam;
camAvailable = true;
camLight = new Color32[frontCam.width * frontCam.height];
} private void Update() { if (!camAvailable)
return;
float ratio = (float)frontCam.width / (float)frontCam.height;
fit.aspectRatio = ratio;
float scaleY = frontCam.videoVerticallyMirrored ? -1f: 1f;
background.rectTransform.localScale = new Vector3(1f, scaleY, 1f);
int orient = -frontCam.videoRotationAngle;
background.rectTransform.localEulerAngles = new Vector3(0, 0, orient);
frontCam.GetPixels32(camLight);
}
}
it does access and display the camera but i cant figure out how to get the light level from it, any solutions would be greatly appreciated :>
Your answer
![](https://koobas.hobune.stream/wayback/20220612170917im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I ToonLitOutline shader transparent? 0 Answers
Telling a shader where shadows should go 0 Answers
Level Unlock script help 1 Answer
Weird shimmer on imported asset 0 Answers
Soft shadow is not soft at all 0 Answers