Example #1
0
        /// <summary>
        /// Deal damage during collision with object, then destroy bullet
        /// </summary>
        /// <param name="collider"></param>
        void OnTriggerEnter(Collider collider)
        {
            if (collider.transform == bulletShooter)
            {
                return;
            }

            DamageTaker dt = collider.GetComponent <DamageTaker>();

            if (dt != null)
            {
                dt.TakeDamage(damageAmount); // hurt the thing we hit...
                Destroy(gameObject);         // remove the bullet
                return;
            }
        }
Example #2
0
        /// <summary>
        /// Called every frame.
        /// Keep lunging at target until it's a certain distance away.
        /// </summary>
        /// <returns></returns>
        public override EnemyState Update()
        {
            Vector3 toAttackTarget = enemy.attackTarget.position - enemy.transform.position;
            float   disSqr         = toAttackTarget.sqrMagnitude;

            if (!lunging)
            {
                timeToLunge = 40;
                lunging     = true;
            }
            else
            {
                timeToLunge -= 1;
            }

            if (timeToLunge <= 0)
            {
                if (toAttackTarget.magnitude < 50)
                {
                    DamageTaker dt = enemy.attackTarget.GetComponent <DamageTaker>();
                    if (dt != null)
                    {
                        dt.TakeDamage(10); // hurt the thing we hit...
                    }
                }
                lunging = false;
            }

            enemy.animation.Play("attack1");

            // transition: if distance > attack threshold and not lunging, switch to pursue

            if (disSqr > enemy.attackDistanceThreshold * enemy.attackDistanceThreshold && !lunging)
            {
                return(new StatePursue());
            }

            return(null);
        }