/// <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;
        }
Exemple #2
0
        UnityEngine.AI.NavMeshAgent nav;  // Reference to the nav mesh agent.


        void Awake()
        {
            // Set up the references.
            player       = GameObject.FindGameObjectWithTag("Player").transform;
            playerHealth = player.GetComponent <Complete.TankHealth> ();
            enemyHealth  = GetComponent <EnemyHealth> ();
            nav          = GetComponent <UnityEngine.AI.NavMeshAgent> ();
        }
        /// <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.
        /// </summary>
        void Start()
        {
            // this stuff is to set up the input for heuristic controls (keyboard/gamepad control) you shouldn't need it for agent control
            vertAxis   = "Vertical" + playerNumber.ToString();
            horzAxis   = "Horizontal" + playerNumber.ToString();
            fireButton = "Fire" + playerNumber.ToString();

            // register ourself as a listener to the health OnTakeDamage event trigger
            health = GetComponent <Complete.TankHealth>();
            Debug.Assert(health, "Warning: could not get agent's Health component");
            if (health)
            {
                health.OnTakeDamage += OnTakeDamage;
            }

            targetHealth = target.GetComponent <Complete.TankHealth>();
            Debug.Assert(targetHealth, "Warning: could not get target's Health component");

            initialized = true;
        }