Graphics Reference
In-Depth Information
13.5.1 Script Breakdown
BattleController is very similar in format to the RaceController class from Metal Vehicle
Doom . This script derives from MonoBehavior so that it can tap into the system functions
called automatically by Unity:
using UnityEngine;
using System.Collections;
public class BattleController : MonoBehavior
{
When the player is hit by another player's projectile, it is deemed as a frag, and the
function Fragged() is called to register it:
public void Fragged ()
{
howmany_frags++;
}
When the player's projectile hits another player, it is a frag, and the function
FraggedOther() is called on the player with the projectile's battle controller:
public void FraggedOther ()
{
howMany_fraggedOthers++;
}
Just as the RaceController from Metal Vehicle Doom had the RaceFinished() function,
the battle controller has its equivalent that will be called by the game controller when the
timer reaches its limit:
public void GameFinished ()
{
isFinished=true;
battleRunning=false;
// find out which position we finished in
int finalBattlePosition= GlobalBattleManager.Instance.
GetPosition( myID );
// tell our car controller about the battle ending
gameObject.SendMessageUpwards("PlayerFinishedBattle",
finalBattlePosition, SendMessageOptions.
DontRequireReceiver);
}
The Boolean variable battleRunning is used to tell whether or not the battle is still
active. When BattleStart() is called, it is set to true and isFinished set to false:
public void BattleStart ()
{
isFinished=false;
battleRunning=true;
}
Search WWH ::




Custom Search