Quantcast
Channel: Questions in topic: "barcode"
Viewing all articles
Browse latest Browse all 8

Need Help regarding Barcodescanning

$
0
0
Hello, I'm using a barcodescanner via USB to insert the numbers into a textfield in Unity When Enter(Return) is pressed. I want to use Unity to acces data from a textfield on the GUI and check if it's above or below 900.000 . And then add 1 to either Can or Flask depending on the number. When pressing "new scan" i want it to delete the data inside of the textfield without deleting the counted number of cans and flasks. I've been using these links to make the code. [Link][1] [Link 2][2] My Question is as follows: Am i doing it correctly? Am i even on the right track? how can i improve/make it work ? I only have to the 11th of May to get it done and working. I'm fairly new to unity, so please try to explain what you are doing with the script the simplest way possible. Thanks for reading! The Code so far: using System; using UnityEngine; using System.Collections; public class ThisismyGUI : MonoBehaviour { private string BarcodeValue = ""; bool UserHitReturn = false; public int Value; public int Can; public int Flask; void Start() { Can = 0; Flask = 0; } void Update () { if (Input.GetButtonDown("Enter")) { try { Value = int.Parse(BarcodeValue.text); } catch (Exception e) { BarcodeValue.text = "0"; } } if (Value > 900000) { Flask++; } else if (Value 1) { Can++; } } void OnGUI() { Menu(); Buttons(); Barcode_Input(); } private void Menu() { GUI.Box(new Rect(10, 10, 100, 200), "Menu"); } private void Buttons() { if (GUI.Button(new Rect(20, 40, 80, 20), "New Scan")) { UserHitReturn = false; BarcodeValue = GUI.TextField(new Rect(200, 50, 100, 20), BarcodeValue); } if (GUI.Button(new Rect(20, 70, 80, 20), "Reset")) { Application.LoadLevel(0); } } private void Barcode_Input() { Event e = Event.current; if (e.keyCode == KeyCode.Return) UserHitReturn = true; else if (false == UserHitReturn) BarcodeValue = GUI.TextField(new Rect(200, 50, 100, 20), BarcodeValue); } } [1]: http://answers.unity3d.com/questions/32241/how-to-make-a-variable-int-having-data-of-a-textfi.html [2]: http://answers.unity3d.com/questions/32241/how-to-make-a-variable-int-having-data-of-a-textfi.html

Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles



Latest Images