- Home /
Need Help regarding Barcodescanning
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 Link 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 < 900000 && 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);
}
}
Answer by fenden · Apr 13, 2015 at 01:13 PM
Difficult issue for me, did you try to add the bar code scanner library to Unity? I don't know how did you solve it ultimately, if you have better resolution, hope you can share it.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer
Capitalize first letter in Textfield Only? 5 Answers
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
Accessing Local Computer Files 2 Answers