{"id":13664632,"url":"https://github.com/nenuadrian/qr-code-unity-3d-read-generate","last_synced_at":"2025-04-10T21:21:34.330Z","repository":{"id":43478528,"uuid":"89125066","full_name":"nenuadrian/qr-code-unity-3d-read-generate","owner":"nenuadrian","description":"Generating a QR code / Scanning a QR code in Unity 3D. Pre-build DLL and sample code from old Unity","archived":false,"fork":false,"pushed_at":"2017-04-23T07:37:36.000Z","size":198,"stargazers_count":95,"open_issues_count":0,"forks_count":22,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-24T18:52:10.781Z","etag":null,"topics":["qrcode","qrcode-generator","qrcode-scanner","unity","unity-3d","unity-generate-qr","unity-qr","unity-scripts","unity2d"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nenuadrian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-23T07:33:25.000Z","updated_at":"2025-02-18T16:29:40.000Z","dependencies_parsed_at":"2022-09-14T09:40:28.263Z","dependency_job_id":null,"html_url":"https://github.com/nenuadrian/qr-code-unity-3d-read-generate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nenuadrian%2Fqr-code-unity-3d-read-generate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nenuadrian%2Fqr-code-unity-3d-read-generate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nenuadrian%2Fqr-code-unity-3d-read-generate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nenuadrian%2Fqr-code-unity-3d-read-generate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nenuadrian","download_url":"https://codeload.github.com/nenuadrian/qr-code-unity-3d-read-generate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248299015,"owners_count":21080448,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["qrcode","qrcode-generator","qrcode-scanner","unity","unity-3d","unity-generate-qr","unity-qr","unity-scripts","unity2d"],"created_at":"2024-08-02T05:03:01.764Z","updated_at":"2025-04-10T21:21:34.300Z","avatar_url":"https://github.com/nenuadrian.png","language":null,"funding_links":[],"categories":["miscellaneous"],"sub_categories":[],"readme":"# qr-code-unity-3d-read-generate\nGenerating a QR code / Scanning a QR code in Unity 3D\n\nAt least at the time when I needed this feature, there were barely any usable tutorials or QR libraries ready to use for Unity (given the older .net framework it uses).\n\nTook me a few days of trial and error until finding and properly building the ZXing library DLL which you can find in the repo.\n\n# Read a QR\n```\nusing ZXing;\nusing ZXing.QrCode;\n\nprivate WebCamTexture camTexture;\nprivate Rect screenRect;\nvoid Start() {\n  screenRect = new Rect(0, 0, Screen.width, Screen.height);\n  camTexture = new WebCamTexture();\n  camTexture.requestedHeight = Screen.height;\n  camTexture.requestedWidth = Screen.width;\n  if (camTexture != null) {\n    camTexture.Play();\n  }\n}\n\nvoid OnGUI () {\n  // drawing the camera on screen\n  GUI.DrawTexture (screenRect, camTexture, ScaleMode.ScaleToFit);\n  // do the reading — you might want to attempt to read less often than you draw on the screen for performance sake\n  try {\n    IBarcodeReader barcodeReader = new BarcodeReader ();\n    // decode the current frame\n    var result = barcodeReader.Decode(camTexture.GetPixels32(), camTexture.width , camTexture.height);\n    if (result != null) {\n      Debug.Log(“DECODED TEXT FROM QR: “ + result.Text);\n    }\n  } catch(Exception ex) { Debug.LogWarning (ex.Message); }\n}\n```\n\n\n# Generate one\n```\nprivate static Color32[] Encode(string textForEncoding, int width, int height) {\n  var writer = new BarcodeWriter {\n    Format = BarcodeFormat.QR_CODE,\n    Options = new QrCodeEncodingOptions {\n      Height = height,\n      Width = width\n    }\n  };\n  return writer.Write(textForEncoding);\n}\n\npublic Texture2D generateQR(string text) {\n  var encoded = new Texture2D (256, 256);\n  var color32 = Encode(text, encoded.width, encoded.height);\n  encoded.SetPixels32(color32);\n  encoded.Apply();\n  return encoded;\n}\n\nTexture2D myQR = generateQR(\"test\");\nif (GUI.Button (new Rect (300, 300, 256, 256), myQR, GUIStyle.none)) {}\n```\n\n\nI am using Unity 5.3.5\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnenuadrian%2Fqr-code-unity-3d-read-generate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnenuadrian%2Fqr-code-unity-3d-read-generate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnenuadrian%2Fqr-code-unity-3d-read-generate/lists"}