Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to change words in an array of words

Hello everyone. im having a bit of problem making this game. Its an endless runner where our player steps on a trigger event that shows and UI with one word (that word its stored in an Arrey with the index of 0). What I want to do is that the next time the Player steps in the same type of trigger the word that will come up its the next one in the Array (so, lets say, the word with Index [1]), and so on, and so on, until I have no more words to show.


Thank you for reading this!

Answers

  • Already tried with a For Loop, but it cycles too fast through the array and only shows the last word everytime

  • You 'just' need to keep the current array index in a variable and increment that each time, e.g.:

    string[] words; // The array with your words

    int index = 0; // The variable we'll use to hold the current array index


    Then when the player steps on the trigger display the word in words[index] and increment index (e.g. index++;) to point to the next word to be used next time the event is triggered. You will also need some logic to handle what happens at the end of the array, e.g.

    //Display words[index]

    index++;

    if(index >= words.length) { // handle what happens at the end of the array}


Sign In or Register to comment.