W
W
WasTabon2020-10-19 18:28:43
C++ / C#
WasTabon, 2020-10-19 18:28:43

How to check for the sequence of elements arriving?

Well, for example, there is a word checking mechanic in games where you need to collect words and I need to somehow implement it, like there is an array with letters, but I don’t know how to check which letters and in what order

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WasTabon, 2020-10-21
@WasTabon

Yeah, I decided how to do it, here is the code, though I haven’t finished the last lines yet

public int inWordCount;
    public int numberInArray = 0;
    public int[] wordsCount;

    public GameObject[] Letters;
    public GameObject[] TakeLetters;

    public bool[] IsLetterActive;

    private void Start()
    {
        for (int i = 0; i < IsLetterActive.Length; i++)
        {
            IsLetterActive[i] = false;
        }
    }

    private void OnTriggerEnter2D(Collider2D col)
    {
        if (TakeLetters[numberInArray] == null)
        {
            TakeLetters[numberInArray] = col.gameObject;
        }
        else
        {
            while (TakeLetters[numberInArray] != null)
            {
                numberInArray++;
                if (TakeLetters[numberInArray] == null)
                {
                    TakeLetters[numberInArray] = col.gameObject;
                }
            }
        }
        if (numberInArray < Letters.Length)
        {
            numberInArray++;
        }
    }

    private void OnPress(InputValue value)
    {
        if (value.isPressed)
        {
            
        }
        else
        {
            for (int inNumber = 0; inNumber < wordsCount.Length; inNumber++)
            {
                for (int InLetters = 0; InLetters < TakeLetters.Length; InLetters++)
                {
                    inWordCount = wordsCount[inNumber];
                    while (inWordCount <= 0)
                    {
                        if (TakeLetters[InLetters])
                        {

                        }
                    }
                }
            }
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question