First download Zxing.net.0.12.0.0.zip, for http://zxingnet.codeplex.com/.
' Unzip to find the Unity folder and then drop it into Unity project.
Using Unityengine;
Using System.Collections;
Using ZXing;
Using Unityengine.ui;
public class Qrcode:monobehaviour
{
public color32[] data;
private bool Isscan;
Public Rawimage cameratexture;
Public Text Txtqrcode;
Private Webcamtexture webcameratexture;
Private Barcodereader Barcodereader;
Private float timer = 0;
IEnumerator Start ()
{
Barcodereader = new Barcodereader ();
Yield return application.requestuserauthorization (USERAUTHORIZATION.WEBCAM);
if (Application.hasuserauthorization (Userauthorization.webcam))
{
webcamdevice[] devices = webcamtexture.devices;
string devicename = Devices[0].name;
Webcameratexture = new Webcamtexture (DeviceName, 400, 300);
Cameratexture.texture = webcameratexture;
Webcameratexture.play ();
Isscan = true;
}
}
void Update ()
{
if (Isscan)
{
Timer + = Time.deltatime;
if (Timer > 0.5f)//0.5 Second scan
{
Startcoroutine (Scanqrcode ());
Timer = 0;
}
}
}
IEnumerator Scanqrcode ()
{
data = Webcameratexture.getpixels32 ();
DECODEQR (Webcameratexture.width, webcameratexture.height);
Yield return new waitforendofframe ();
}
private void Decodeqr (int width, int height)
{
var br = Barcodereader.decode (data, width, height);
if (br! = NULL)
{
Txtqrcode.text = Br. Text;
Isscan = false;
Webcameratexture.stop ();
}
}
}
Unity3d open Local camera scan QR code