This article shares the specific code for Unity to generate text verification code for your reference. The specific content is as follows
Text verification code
Since I often use Unity for webgl version development, I see that there are many verification codes for user login on the website. Drawing from related blogs, I wrote Unity's tool-type text verification code, the code is as follows:
Tool class: VerificationCode
using ; using ; using ; /// <summary> /// This tool class is: Generate verification code/// Author: hys/// Time: 2019.12.30/// Email: 840917807@/// </summary> public class VerificationCode { private static char[] constant = { '0','1','2','3','4','5','6','7','8','9', 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' }; /// <summary> /// Get randomly generated verification code /// </summary> /// <param name="Length">Length</param> /// <returns></returns> public static string SetDeleKey(int Length) { StringBuilder newRandom = new StringBuilder(62); rd = new (); for (int i = 0; i < Length; i++) { (constant[(62)]); //(62) Return a non-negative random number less than 62, Append splices the random codes of Length times } return (); } }
Unity Scripts
using ; using ; using UnityEngine; using ; public class HuangVerificationCodeTextScripts : MonoBehaviour { private Text verificationCodeText; //Verification code Text. private void Awake() { init(); } void Start() { } void Update() { } /// <summary> /// Initialize /// </summary> private void init() { verificationCodeText = ("VerificationCodeText").GetComponent<Text>(); } /// <summary> /// Generate verification code /// </summary> /// <param name="length">Verification code length</param> /// <returns> Verification code for string type</returns> public string generateVerificationCode(int length) { string code= (length); = code; return code; } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.