Ejemplo n.º 1
0
        public void Kill()
        {
            if (_pool.Despawn(this))
            {
                using (var lst = TempCollection.GetList <Transform>())
                {
                    GameObjectUtil.GetAllChildrenAndSelf(this.transform, lst);
                    for (int i = 0; i < lst.Count; i++)
                    {
                        var rb = lst[i].GetComponent <Rigidbody>();
                        if (rb != null && !rb.isKinematic)
                        {
                            rb.velocity        = Vector3.zero;
                            rb.angularVelocity = Vector3.zero;
                        }

                        var rb2 = lst[i].GetComponent <Rigidbody2D>();
                        if (rb2 != null && !rb2.isKinematic)
                        {
                            rb2.velocity        = Vector3.zero;
                            rb2.angularVelocity = 0f;
                        }

                        //NOTE - this is handled by the components themselves
                        //Notification.PurgeHandlers(lst[i].gameObject);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void Kill()
 {
     if (!_pool.Despawn(this))
     {
         Object.Destroy(this.gameObject);
     }
     else
     {
         //TODO - need a cleaner way of doing this
         using (var lst = TempCollection.GetList <Rigidbody>())
         {
             this.transform.GetComponentsInChildren <Rigidbody>(lst);
             var e = lst.GetEnumerator();
             while (e.MoveNext())
             {
                 e.Current.velocity        = Vector3.zero;
                 e.Current.angularVelocity = Vector3.zero;
             }
         }
         using (var lst = TempCollection.GetList <Rigidbody2D>())
         {
             this.transform.GetComponentsInChildren <Rigidbody2D>(lst);
             var e = lst.GetEnumerator();
             while (e.MoveNext())
             {
                 e.Current.velocity        = Vector2.zero;
                 e.Current.angularVelocity = 0f;
             }
         }
     }
     if (this.OnKilled != null)
     {
         this.OnKilled(this, System.EventArgs.Empty);
     }
 }