QR / Barcode Reader

It recognizes QR / Barcode.

Make QR / Barcode Scene
Start / Stop Reader
Use Reading Information

Make the QR / Barcode Scene

  1. Install MAXST AR SDK for Unity.

  2. Create the new scene.

  3. Delete the Main Camera that exists by default and add 'Assets > MaxstAR > Prefabs > ARCamera' to the scene.

    codePrefab

    ※ If you build an application, you must add a License Key to ARCamera.

  4. Create an empty object and add 'Assets > MaxstARSamples > Scripts > CodeScanSample' as a component.

    codeSample

  5. Add a button and two Texts. And then drag and drop those elements into the GameObject's Insepctor window.

    codeText

  6. Set the StartCodeScan () function in the Click event of the Button.

    codeBtn

  7. Build and run the app. Then, scan the QRCode or barcode with the camera and the code will be printed on the screen. ※ You can download the target QRCode used in the tutorial from the QRCode Target link.

  8. If you have a webcam connected, you can test it in the Unity Editor environment by pressing the Play button in Unity.

Start / Stop Reader

To start / stop Reader, refer to the following code.

>CodeScanSample.cs

void Update()
{
    ...
    TrackerManager.GetInstance().StartTracker(TrackerManager.TRACKER_TYPE_CODE_SCANNER);
    ...
}

void OnApplicationPause(bool pause)
{
    ...
    TrackerManager.GetInstance().StopTracker();
    ...
}

void OnDestroy()
{
    TrackerManager.GetInstance().StopTracker();
    TrackerManager.GetInstance().DestroyTracker();
}

Use Reading Information

When you point the camera to QR / Barcode, the code name will be displayed on the screen. Refer to the following code to use the Reading information.

>CodeScanSample.cs

void Update()
{
    ...
    IntPtr codeScanResultPtr = TrackerManager.GetInstance().GetCodeScanResult();
    if (codeScanResultPtr == IntPtr.Zero)
    {
        return;
    }
    string strCode = Marshal.PtrToStringAnsi(codeScanResultPtr);
    if (strCode != null && strCode.Length > 0)
    {
        targetText.text = strCode;
    }
}