/// <summary> /// Part of UnityEngine::Monobehavior (which is Base class of Agent and Unity's primary component class). /// Start() is called immediately before the first frame of the game is run and used for initialization. /// Typically, you cache references here into member variables for easy reference later. /// Note that during training, Start() will only get called once, at beginning of training. /// If you want to initialize something for each episode, use OnEpisodeBegin() /// </summary> protected override void Start() { base.Start(); // TankAgentBase does some hosuekeeping for us // you can add code to do one-time initialization here // for this agent, we're adding health related stuff so we can reward based on damages done // register ourself as a listener to the health OnTakeDamage event trigger health = GetComponent <Complete.TankHealth>(); Debug.Assert(health, "Warning: could not get agent's TankHealth component"); if (health) { health.OnTakeDamage += OnTakeDamage; } shooting = GetComponent <Complete.TankShooting>(); Debug.Assert(health, "Warning: could not get agent's TankShooting component"); targetHealth = target.GetComponent <Complete.TankHealth>(); Debug.Assert(targetHealth, "Warning: could not get target's Health component"); textOutput = GetComponent <AgentTextDisplayer>(); Debug.Assert(textOutput, "Warning: could not get AgentTextDisplayer component"); initialized = true; }
private void Awake( ) { TankShooting = GetComponent <Complete.TankShooting>(); NavMeshAgent = GetComponent <NavMeshAgent>(); }