Question by
andrey231102 · Jan 30 at 03:06 PM ·
c#scripting problemlistdatacollections
how is it possible that my List has count = 3, but after im trying to compare onClick obhects name it says that my list is empty
public class TaskSetter : MonoBehaviour { [SerializeField] private TMP_Text _text; [SerializeField] private GridViewer _gridViewer;
private readonly List<string> _iconsToFind = new List<string>();
public event UnityAction AnswerAccepted;
private void Start()
{
for (int i = 0; i < _gridViewer.AmountOfLevels; i++)
_iconsToFind.Add(_gridViewer.transform.GetChild(i).GetChild(Random.Range(0, _gridViewer.transform.GetChild(i).childCount)).GetChild(0).name);
_text.text = "Find " + _iconsToFind[0];
}
private void OnMouseDown()
{
Debug.Log(_iconsToFind.Count);
}
public void CheckAnswer(string name)
{
if (_iconsToFind.Contains(name))
{
Debug.Log(_iconsToFind.Count);
//tile.Bounce();
AnswerAccepted?.Invoke();
}
else
{
Debug.Log("NotOkay");
//tile.EaseInBounce();
}
}
}
public class Tile : MonoBehaviour { [SerializeField] private TaskSetter _taskSetter;
private string _iconName;
public string IconName => _iconName;
private void Start()
{
_iconName = gameObject.transform.GetChild(0).name;
}
private void OnMouseDown()
{
_taskSetter.CheckAnswer(_iconName);
}
}
Comment
Your answer
Follow this Question
Related Questions
Need help to generate a random assortment of 4 buttons - C# 0 Answers
A more optimized way to adjust duplicate integer values In a list? 0 Answers
Variables changes even on pause 0 Answers
How to get component of gameobjects in a list 2 Answers
[Quiz Game] How to prevent Question asked twice. HELP 1 Answer