I'm reading through a tutorial for making an RTS in Unity, and in certain scripts it wants you to make a Player field and then OnStart(){ transform.root.GetComponent}. I am not quite getting what that does or what purpose it serves.
Player.cs is added as a component to the game object "Player". Player.cs is the following:
public class Player : MonoBehaviour {
public string username { get; set; }
public bool human { get; set; }
}
Then on another script which is also attached to the Player (gameobject) as a component:
protected Player player;
protected void Start ()
{
player = transform.root.GetComponent<Player>();
}
This is instructed: http://stormtek.geek.nz/rts_tutorial/part2.php right under "Camera Input". There is a description there, but I am confused by it since it does not allow you to actually interact with the game object Player, but the instance of the Player script.
I'm sorry if this was poorly worded, I can't think of a better way to ask this question. I am completely confused as to why it asks you to do this and what it actually does. I'm also very confused about how to reference instances of a class that are attached to a game object, and if the snippet in question assists with that (I can remove the snippet and things seem to work fine).
Edit: I have looked at the unity documentation on game objects, transform, root, getcomponents and other related methods.