Graphics Reference
In-Depth Information
playerStarts [i] = (Vector3) startPoints [i].position;
playerRotations [i] = ( Quaternion ) startPoints [i].rotation;
}
One important thing to note is that the first player listed in the playerPrefabList (set
in the Unity editor Inspector window) should always be the user's player prefab and not
an AI—the script is based on the assumption that the first player will always be the one to
focus on for UI, scoring, and camera following, etc.:
SpawnController.Instance.SetUpPlayers( playerPrefabList,
playerStarts, playerRotations, playerParent, numberOfBattlers );
playerTransforms=new ArrayList();
// now let's grab references to each player's controller script
playerTransforms = SpawnController.Instance.
GetAllSpawnedPlayers();
playerList=new ArrayList();
for ( int i = 0; i < numberOfBattlers; i++ )
{
Transform tempT= (Transform)playerTransforms[i];
CarController_TB tempController=
tempT.GetComponent<CarController_TB>();
playerList.Add(tempController);
BaseAIController tempAI=tempController.GetComponent
<BaseAIController>();
tempController.Init ();
The AI players in Tank Battle are going to need to know which gameObject the player is,
to be able to chase and track it. We start the game with all of the tanks defaulting to look for
the user. This behavior will, in fact, be overridden by the AI if it gets close enough to another
AI opponent, as it will attack a close target regardless of whether or not it is the user.
Here the condition is to check to see whether the loop (i) is at a value greater than 0 so
that we know this is not a user (remember that users are always the first in the playerPrefab
array and will always be 0 index):
if( i>0 )
{
The SpawnController.Instance.GetPlayerGO() function gives back the gameObject
for a specific player based on its ID passed in as a parameter:
// grab a ref to the player's gameobject for
// later use
playerGO1 = SpawnController.Instance.GetPlayerGO( 0 );
Next, the user's transform is passed on to the AI player with a call to SetChaseTarget:
// tell AI to get the player!
tempAI.SetChaseTarget( playerGO1.transform );
Search WWH ::




Custom Search