Graphics Reference
In-Depth Information
if(battleControllers==null)
{
Debug.Log ("GetPosition battleControllers is
NULL!");
return -1;
}
if(battleControllers.ContainsKey(ofWhichID)==false)
{
Debug.Log ("GetPosition says no battle controller
found for id "+ofWhichID);
return -1;
}
Next, the code grabs a reference to the BattleController component attached to the
player we want to find out about and keeps it in focusPlayerScript:
// first, we need to find the player that we're trying to
// calculate the position of
focusPlayerScript= (BattleController)
battleControllers[ofWhichID];
This code is very similar to the race position checking from the global race manager,
except there is no waypoint, lap, or distance checking; instead, it is all based on frag num-
bers. The script begins with the assumption that the player is in last place, as the logic
works backward in terms of calculating the score rank:
myPos = numberOfBattlers;
for ( int b = 1; b <= numberOfBattlers; b++ )
{
// assume that we are behind this player
isAhead = false;
Step 1 is to get a reference to the current battleController instance we need to talk to,
which is stored in the variable tempRC:
// grab a temporary reference to the 'other' player
// we want to check against
tempRC = (BattleController) battleControllers [b];
A quick null check is made to make sure the game does not crash if a player were to
get prematurely deleted during play or as the game ends:
// if player 2 happens to be null (deleted for
// example) here's a little safety to skip this
// iteration in the loop
if(tempRC==null)
continue;
Comparing the player we want to look at with its own battleController would be
pointless, so the script compares the IDs of each battleController before any sort of score
checking takes place:
if ( focusPlayerScript.GetID() != tempRC.GetID() )
{
Search WWH ::




Custom Search