Example #1
0
        new void Awake()
        {
            base.Awake();

            // Add the view trigger
            viewTrigger           = gameObject.AddComponent <SphereCollider>();
            viewTrigger.isTrigger = true;
            viewTrigger.radius    = viewDistanceRadius;

            // Add a kinematic rigidbody for triggers
            // aiRigidbody = GetComponent<Rigidbody>();
            // if (!aiRigidbody) aiRigidbody = gameObject.AddComponent<Rigidbody>();
            // aiRigidbody.isKinematic = true;

            // Setup the nav mesh agent
            health = GetComponent <AIHealth>();

            // Set the objects date of birth
            dob = Time.time;

            var hasDestination = GetComponent <AIDestination>();

            if (!hasDestination)
            {
                gameObject.AddComponent <AIDestination>();
            }
        }
Example #2
0
        /// <summary>
        /// Gets the healthiest character within the view distance.
        /// **Note:** The other character must have the "Health" component to qualify.
        /// </summary>
        /// <returns></returns>
        public AIBrain Healthiest(IEnumerable <AIBrain> list = null)
        {
            var items = list == null ? surroundingBrains : list;

            if (items.Count() == 0)
            {
                return(null);
            }
            return(items
                   .Aggregate((AIBrain)null, (curr, item) => {
                AIHealth currHealth = curr.GetComponent <AIHealth>();
                AIHealth itemHealth = item.GetComponent <AIHealth>();
                if (!currHealth || !itemHealth)
                {
                    return curr;
                }
                if (itemHealth.health > currHealth.health)
                {
                    return item;
                }
                return curr;
            }));
        }
Example #3
0
 public void ApplyDamage(AIHealth otherHealth, float amount)
 {
     otherHealth.RemoveHealth(amount);
 }