示例#1
0
        /// <summary>
        /// Helper method which can send damage to a specific gameobject.
        /// It first gets the closest parent that has a damage handler (<see cref="IDamageHandler"/>) and then all other damage handlers on that gameobject.
        /// </summary>
        public static void SendDamage(this GameObject gameObject, DamageEventArgs args)
        {
            // Try spawning debris
            DebrisManager.instance.TrySpawnDebris(gameObject, args.hitPoint, args.hitNormal, DebrisSpawn.BulletDecal | DebrisSpawn.DebrisParticles);

            // Get damagehandle in parents
            var dh = gameObject.GetComponentInParent <IDamageHandler>();

            // Does have a damage handler=
            if (dh != null)
            {
                // Read all damage handlers in case there are multiple on the handler object.
                var dhs = ListPool <IDamageHandler> .Get();

                dh.gameObject.GetComponents(dhs);

                // Send damage to all handlers
                for (int i = 0; i < dhs.Count; i++)
                {
                    dhs[i].TakeDamage(args);
                }

                ListPool <IDamageHandler> .Return(dhs);
            }
        }
示例#2
0
 /// <summary>
 /// Handler for <see cref="EntityModel.onDamageTaken"/>
 /// </summary>
 protected virtual void OnHandleDamage(DamageEventArgs args)
 {
     this.health -= args.damage * this.entity.model.damageTaken.Get();
     if (this.health <= 0)
     {
         this.entity.model.death.ForceStart(); // CanDie will always be met here
     }
 }
示例#3
0
        public void TakeDamage(DamageEventArgs args)
        {
            this.health -= args.damage;

            if (this.health <= 0)
            {
                Die();
            }
        }
示例#4
0
        public void Update()
        {
            if (this._traveled > this.range)
            {
                Destroy(this.gameObject);
                return;
            }

            float      moved = this.flightSpeed * Time.deltaTime;
            RaycastHit rh;

            if (Physics.Raycast(this.transform.position, this.transform.forward, out rh, moved, this.hitMask))
            {
                rh.collider.gameObject.SendDamage(DamageEventArgs.Create(this.damage, rh.point, rh.normal, this.physicalForce));
                PrefabPool.instance.Return(this.gameObject);
            }

            this._traveled         += moved;
            this.transform.position = this.transform.position + (this.transform.forward * moved);
        }
示例#5
0
 /// <summary>
 /// Fires <see cref="EntityModel.onDamageTaken"/>, implemented from <see cref="IDamageHandler.TakeDamage(DamageEventArgs)"/>
 /// </summary>
 public void TakeDamage(DamageEventArgs args)
 {
     this.entity.model.onDamageTaken.Fire(args);
 }
示例#6
0
 public void TakeDamage(DamageEventArgs args)
 {
     this.reciever.AddForceAtPosition(args.hitNormal * -1f * args.physicalForce, args.hitPoint);
 }