I’m having some confusion on understanding the script architecture and logic in regards to the PluggableAI Tank Tutorial game. Specifically, I am having trouble understanding how the GameManager and the TankManager scripts work together to start the game.
I have three questions.
Links to the Tank Tutorial and the introduction scriptable objects below.
1.) m_Tanks[ ] is an array of type TankManager. This means that it has all attributes of the TankManager?? Is this like inheritance?
So… if I understand this correctly:
The game starts, and the GameManager calls SpawnAllTanks() from the Start() function. SpawnAllTanks() then creates the Player’ and AI Tanks.
So when the GameManager script says inside the SpawnAllTanks():
private void SpawnAllTanks()
{
//Manually setup the player at index zero in the tanks array
m_Tanks[0].m_Instance =
Instantiate(m_TankPrefabs[0], m_Tanks[0].m_SpawnPoint.position, m_Tanks[0].m_SpawnPoint.rotation) as GameObject;
m_Tanks[0].m_PlayerNumber = 1;
m_Tanks[0].SetupPlayerTank();
// Setup the AI tanks
for (int i = 1; i < m_Tanks.Length; i++)
{
// ... create them, set their player number and references needed for control.
m_Tanks[i].m_Instance =
Instantiate(m_TankPrefabs[i], m_Tanks[i].m_SpawnPoint.position, m_Tanks[i].m_SpawnPoint.rotation) as GameObject;
m_Tanks[i].m_PlayerNumber = i + 1;
m_Tanks[i].SetupAI(wayPointsForAI);
}
}
m_Tanks is declared as a variable public variable of type TankManager above.
Because the m_Tanks[0] is of type TankManager, it has a public variable m_Instance that can be accessed by the dot operator? So is this kind of like calling a get/set property and getting the variable to a value? But in this case, we have a variable called m_Instance of type GameObject (inside the TankManager script) and it gets “set” as a tank prefab.
Also, why does the “m_” not show up in the inspector? The GameManager only displays “Tanks”.
2.) Inside the TankManager there is a script called SetupPlayerTank, and I am having trouble understanding the parts of the script that say:
m_Movement = m_Instance.GetComponent<TankMovement> ();
Why is the “m_Instance” before the GetComponent portion?
Is this because the GameManager made the m_Tanks[ ] array, then the TankManager assigned each one to a GameObject? So each one has it’s own m_Instance, and the “GetComponent” is grabbing the reference to the component attached to the tank prefab (
3.) The TankManager is not a monobehaviour and not a Serializable Object.
I tried to understand Unity’s introduction to Scriptable Objects, and I thought that they said something about not wanting any scripts that aren’t derived from Scriptable Objects. What are the consequences (or pros and cons?) to the TankManager not being a Monobehaviour or a Scriptable Object. Does this basically mean that it can’t be dragged and dropped into the inspector since it is not a gameObject and that the data in the script is lost after the game is stopped after playing (after runtime is over)?
I know this is a lot. Thanks in advance for all your input guys!
PluggableAI Tank Tut Link:
Introduction to Scriptable Objects: