using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
public class SecurityKeypadKeys : MonoBehaviour
{
public TextMesh text;
private int counter = 0;
private void Start()
{
}
private void OnMouseDown()
{
string[] digits = Regex.Split(transform.name, @"\D+");
foreach (string value in digits)
{
int number;
if (int.TryParse(value, out number))
{
counter++;
if (counter < 8)
{
text.text += number.ToString();
}
}
}
}
}
I used a break point and found that if I press on a button of number 1 and press on it 8 times then it will stop writing the next number 1 to the text but then if I click on the number 2 it will write to the text another 8 times of the 2 number.
but I want that the player will be able to type only 8 numbers no matter if it's 12345678 or 88888888 or 0000000 or 56498611 and then if the player keep typing it will not add anymore numbers to the text.
The problem is that the script is attached to 10 cubes act like buttons. so each time I click on another cube(button) it's reseting the counter to 0.