A simple and easy-to-use Unity package for generating QR codes at runtime and displaying them on UI elements.
- Overview
- Features
- Dependencies
- Compatibility
- Installation
- How To Use
- Configuration
- Testing
- License
- Acknowledgments
- Featured In
This package provides a QRCodeGenerator MonoBehaviour that can be attached to a GameObject to render QR codes to a RawImage component. It is built upon the widely-used ZXing.Net library.
Ideal for sharing links, game levels, or other data in Unity applications.
- Generate QR codes from any string data and display the generated code on a
UnityEngine.UI.RawImage. - Automatically adjusts the QR code size to fit the target
RawImagecomponent. - Configurable border margin.
- Includes unit tests that can be launched in Test Runner.
- Unity UI Package (
com.unity.ui) - This package includes a pre-compiled version of
zxing.unity.dll, which provides QR code generation functionality using the ZXing.Net library. The DLL is located in thezxing.unityfolder of the package.
Important: This package has only been tested on Unity version 6.1 for Editor, iOS and Android. Compatibility with other Unity versions and platforms is not guaranteed.
You can install this package in Unity's Package Manager using the "Add package from git URL" option.
- Open the Package Manager (
Window > Package Manager). - Click the
+button in the top-left corner. - Select "Add package from git URL...".
- Enter the repository's HTTPS URL (e.g.,
https://github.com/shirleyman/unity-qrcode.git) and click "Add".
- Clone this repository.
- Copy the package contents to your Unity project's
Packagesdirectory.
- Create a
RawImagecomponent in your scene (GameObject > UI > Raw Image). - Add the
QRCodeGeneratorcomponent to the same GameObject. - The component will automatically find the
RawImageon the same GameObject. - In your own script, get a reference to the
QRCodeGeneratorcomponent. - Call the
GenerateQRCode(string textToEncode)method to generate and display the code.
using UnityEngine;
using OrbitalNine.QRCode; // Make sure to include the namespace
public class MyQRCodeController : MonoBehaviour
{
public QRCodeGenerator qrCodeGenerator;
public string textToEncode = "https://unity.com/";
void Start()
{
if (qrCodeGenerator == null)
{
qrCodeGenerator = GetComponent<QRCodeGenerator>();
}
// Generate the QR code on start
if (qrCodeGenerator != null)
{
qrCodeGenerator.GenerateQRCode(textToEncode);
}
}
}The QRCodeGenerator component has the following configurable properties in the Inspector:
- QR Code Size: The width and height of the generated QR code texture in pixels. On
Awake()andReset(), this value is automatically set to the smaller of theRawImage's width or height. - QR Code Margin: The width of the white border around the QR code, in modules (pixels of the QR code matrix).
- QR Code Image: A reference to the
RawImagecomponent used for display. If not assigned, the component will attempt to find one on the same GameObject.
This package includes a suite of tests for both runtime and editor modes. You can run these tests using the Unity Test Runner window (Window > General > Test Runner).
This project is licensed under the MIT License. See LICENSE for details.
- License: Apache License 2.0
- Source: https://github.com/micjahn/ZXing.Net
- License Text: See LICENSE-APACHE-2.0 or visit http://www.apache.org/licenses/LICENSE-2.0
This package uses ZXing.Net, a .NET port of the ZXing barcode library, which is licensed under the Apache License 2.0.
- Brain It On! (iOS, Android) by Orbital Nine Games. Displays a QR code on the level completion screen, allowing streamers and players to easily share a link to the level they played.