- Home /
Question by
EinfachFinn · Mar 06 at 09:04 PM ·
scripting problemuibutton
(UI-Builder) Button Change Variable
Hey, I have this script and a few buttons placed in the UI Builder. How do I get a button to change the Camera variable?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using OpenCvSharp;
public class FaceDetector : MonoBehaviour
{
public int Camera;
WebCamTexture _webCamTexture;
CascadeClassifier cascade;
// Start is called before the first frame update
void Start()
{
WebCamDevice[] devices = WebCamTexture.devices;
_webCamTexture = new WebCamTexture.devices[Camera].name;
_webCamTexture.Play();
cascade = new CascadeClassifier(Application.dataPath + @"haarcascade_frontalface_default.xml");
}
// Update is called once per frame
void Update()
{
GetComponent<Renderer>().material.mainTexture = _webCamTexture;
Mat frame = OpenCvSharp.Unity.TextureToMat(_webCamTexture);
findNewFace(frame);
}
void findNewFace(Mat frame)
{
var faces = cascade.DetectMultiScale(frame, 1.1, 2, HaarDetectionType.ScaleImage);
if (faces.Length >= 1)
{
Debug.Log(faces[1].Location);
}
}
}
Comment
Do you mean UI Elements
/ UI Toolkit
's UI Builder? I ask just to be sure.
Your answer
Follow this Question
Related Questions
UI Button - get reference to the parameter passed to function under OnClick() 1 Answer
[SOLVE] OnMouseEnter not working on UI elements 2 Answers
Pressing space calls the wrong function 1 Answer
How to get an array of all Buttons attached to a Panel? 2 Answers
UI Buttons to work continuously when pressed and held for sometime 1 Answer