Graphics Reference
In-Depth Information
public class CarController_MVD : BaseVehicle
{
After the variable declarations, the Start() function here overrides the Start() from the
BaseVehicle class. Even though this overridden version features no actual functionality, it
is important to do so since the original function (the function we are overriding) called
Init() immediately, and we do not want to do that here. The Init() function will be called
by the game controller for this game instead:
public override void Start ()
{
// we are overriding the Start function of BaseVehicle
// because we do not want to initialize from here! Game
// controller will call Init when it is ready
}
For the CarController_MVD class, there are two Init() functions, one for the gen-
eral initialization and another called InitAI() for dealing with the initialization of the AI
system.
Init() begins by caching common variables:
public override void Init ()
{
Debug.Log ("CarController_MVD Init called.");
// cache the usual suspects
myBody= rigidbody;
myGO= gameObject;
myTransform= transform;
The variable canRespawn is used to restrict respawning when a respawn is already in
progress. At the start of the game, we allow respawning:
// allow respawning from the start
canRespawn=true;
The maximum acceleration value used for AI players will be altered to make for a
more interesting race, such as speeding up an AI car so that it can catch up when it falls
too far behind. For this reason, the original acceleration value needs to be stored for when
we want to put the maximum acceleration value back to its original amount:
// save our accelMax value for later use, in case we need to
// change it to do AI catch up
originalAccelMax= accelMax;
A default input controller is added to all players, the Keyboard_Input class:
// add default keyboard input if we don't already have one
if( default_input==null )
default_input= myGO.AddComponent<Keyboard_Input>();
The BasePlayerManager should be attached to the player's gameObject. It will be
needed later, so we store a reference to it in myPlayerController, then call its Init() func-
tion for the player manager to initialize:
Search WWH ::




Custom Search