- Home /
My bool function isnt running in my code and i cant figure out why.
Here is code it can be copied and pasted into a project as it uses its own UI and etc
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text;
using System.IO;
using System;
using System.Text.RegularExpressions;
[ExecuteAlways]
public class Scan : MonoBehaviour
{
public string SaveName;
public CVSDATA CurrentInput;
public List<CVSDATA> ScannerData = new List<CVSDATA>();
string tempPrice;
public bool Pressed;
[System.Serializable]
public class CVSDATA
{
public string rowDataPLU;
public string rowDataName;
public string rowDataPrice;
public int rowDataCount;
}
void OnGUI()
{
CurrentInput.rowDataPLU = GUI.TextArea(new Rect(0, Screen.height - 90, Screen.width, 30), CurrentInput.rowDataPLU);
CurrentInput.rowDataPLU = Regex.Replace(CurrentInput.rowDataPLU, @"[^0-9]", string.Empty);
tempPrice = GUI.TextArea(new Rect(0, Screen.height - 60, Screen.width, 30), tempPrice);
if (GUI.Button(new Rect(0, Screen.height - 30, Screen.width, 30), "Scan"))
{
Pressed = true;
Debug.Log("Button Pressed");
}
}
// Update is called once per frame
void Update()
{
if (tempPrice != null)
{
tempPrice = Regex.Replace(tempPrice, @"[^0-9 .]", string.Empty);
CurrentInput.rowDataPrice = tempPrice;
}
if(Pressed)
{
for (int x = 0; x < ScannerData.Count; x++)
{
if (ScannerData[x].rowDataPLU != CurrentInput.rowDataPLU)
{
ScannerData.Add(CurrentInput);
Pressed = false;
}
else
{
ScannerData[x].rowDataCount = ScannerData[x].rowDataCount + CurrentInput.rowDataCount;
Pressed = false;
}
}
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612210152im_/https://answers.unity.com/themes/thub/images/avi.jpg)