Game Development Reference
In-Depth Information
Debug.Log (W.WizardName);
}
}
}
You can also enumerate through all wizards outside a foreach loop by accessing the
Enumerator object directly, as shown in the following code sample 6-10:
void Update()
{
//Press space to list all wizards in scene
if(Input.GetKeyDown(KeyCode.Space))
{
//Get Enumerator
IEnumerator WE = Wizard.FirstCreated.GetEnumerator();
while(WE.MoveNext())
{
Debug.Log(((Wizard)WE.Current).WizardName);
}
}
}
Strings and regular expressions
Working with text data is critical and for many reasons. If you need to display
subtitles, show in-game text, and implement localization functionality (supporting
multiple languages), then you would be working with text, specifically with Text
Assets. In Unity, Text Assets refer to any text files included in the Unity project, and
each asset is treated as one long string even when multiple lines are involved (each
line is separated by a \n escape character). Once your code is presented with a string
like this, however, there're typically many ways in which you'll want to process it.
Let's see some common but important string operations.
Null, empty strings, and white space
When processing strings, you can't always guarantee validity; sometimes, strings are
badly formed and don't make sense. For this reason, you'll frequently need to validate
them before processing. A common way to validate them initially is to see whether a
string is null, and then (if not null) check the string's length, because if the length is 0 ,
then the string is empty and, therefore, invalid, even though it's not null .
 
Search WWH ::




Custom Search