Tools

QR Coder Unity

QRCoder.Unity

qrcoder-unity MyGet Build Status

Info

QRCoder.Unity is an extension for the popular QRCoder.NET library. It allows you to render QRCodes as Texture2D objetcs for usage in Unity projects. Please open issues in this repository only if they are Unity-specific. For general problems/ideas/enhancement requests concerning the QR code funtionalities, please open an issue in the main QRCoder repository.

For usage information see the demo code below. For more general information check the QRCoder Wiki.

Installation

Either checkout this Github repository or install QRCoder.Unity via NuGet Package Manager. If you want to use NuGet just search for “QRCoder.Unity” or run the following command in the NuGet Package Manager console:

PM> Install-Package QRCoder.Unity

Note: The NuGet feed contains only stable releases. If you wan’t the latest build add one of the following urls to the “Package Sources” of Visual Studio’s NuGet Package Manager options.

NuGet V3 feed URL (Visual Studio 2015+): https://www.myget.org/F/qrcoder-unity/api/v3/index.json

NuGet V2 feed URL (Visual Studio 2012+): https://www.myget.org/F/qrcoder-unity/api/v2

Usage & Demos

Note: For a complete up’n’running solution have a look at the demo project, provided in this repository. Demo animation

Preparation

For use in Unity projects you should install the QRCoder.Unity library via NuGet for Unity3D-package manager. So (if not done already) you should install NuGet for Unity first, before doing the next steps. (If you install the QRCoder.Unity package via NuGet from Visual Studio/Monodevelop, Unity won’t recognize the Dlls correctly.) After installation of NuGet for Unity, restart the Unity IDE.

General usage

To use QRCoder.Unity in an Unity project do the following steps:

  • Install the package QRCoder.Unity via NuGet for Unity package manager.
  • Add a new script (or edit an existing script).
  • Add the following using statements to the script’s header section
using QRCoder;
using QRCoder.Unity;
  • Create the QR code and render it as Texture2D.
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("Hello world!", QRCodeGenerator.ECCLevel.Q);
UnityQRCode qrCode = new UnityQRCode(qrCodeData);
Texture2D qrCodeAsTexture2D = qrCode.GetGraphic(20);
  • Attach the QR code texture to a game object. (The following example uses an cube object named “Cube”.)
GameObject.Find("Cube").GetComponent<Renderer>().material.mainTexture = qrCodeAsTexture2D;

QRCoder.Unity is project by Raffael Herrmann and was first released in 11/2018. It’s licensed under the MIT license and based on the work of QRCoder.