- Home /
counting a letter for a word from an array?
Hello,
I´m writing a very simple First-Person-Point&Click Game, where in one level you must collect letters of a word (which is a part of an array) to go into the next level. The collecting works, but now I want to have a HUD, where you see the the numbers of remaining letters.
Does anyone know, how you can count the letters of a (any) word, which cames from an array?
My Unity Version is 4.5.1f3 and my Code is written in UnityScript aka JavaScript
Regards,
TemplateR
Answer by OncaLupe · Dec 13, 2015 at 07:49 PM
A string can be treated like an array, so you can get lengths and individual letters in the same way as array elements. You can also convert it to a char array if needed.
string wordToFind = "Unity";
Debug.Log(wordToFind.Length); //Prints 5
Debug.Log(wordToFind[0]); //Prints U
char[] charsToFind = wordToFind.ToCharArray();
Can I access the array from another scirpt for my HUD/UI-Script? If yes, how it look like?