コード例 #1
0
        void Start()
        {
            SoundManager.GetInstance().PlayOneShot(AudioRepository.LoadExplosionAudio(missile.audioID));

            animator.AnimationCompleted = delegate(tk2dSpriteAnimator sprite, tk2dSpriteAnimationClip clip)
            {
                animator.AnimationCompleted = null;

                missile = null;

                Destroy(gameObject);
            };

            if (missile.WOE != 0)
            {
                Collider2D[] hits = Physics2D.OverlapCircleAll(this.transform.position, this.missile.WOE);

                IList <GameObject> hitedCache = new List <GameObject>();
                foreach (Collider2D hit in hits)
                {
                    MonsterEntity2D entity = hit.gameObject.GetComponent <MonsterEntity2D>();

                    if (entity != null && !hitedCache.Contains(entity.gameObject))
                    {
                        entity.OnMissileHit(sender, missile, this.transform.position);

                        hitedCache.Add(hit.gameObject);
                    }
                }

                hitedCache.Clear();
            }
        }
コード例 #2
0
        protected void OnCollisionEnter2D(Collision2D coll)
        {
            #region Hit Monster
            if (coll.gameObject.layer == LayerMaskDefines.MONSTER.id)
            {
                MonsterEntity2D entity = coll.gameObject.GetComponent <MonsterEntity2D>();

                if (entity.machine.currentState.GetName() != StateTypes.Dead.ToString())
                {
                    if (data.WOE == 0)
                    {
                        entity.OnMissileHit(owner, data, coll.contacts[0].point);
                    }

                    ProcessCollision(coll.contacts[0].point);

                    ProcessPhsysicsType(coll.gameObject, data.physicsType);
                }
                else
                {
                    body2D.velocity = velocity;

                    Collider2D[] colliders = coll.gameObject.GetComponents <Collider2D>();

                    for (int index = 0; index < colliders.Length; index++)
                    {
                        Physics2D.IgnoreCollision(GetComponent <Collider2D>(), colliders[index]);
                    }
                }
            }
            #endregion

            #region Hit Missile
            if (coll.gameObject.layer == LayerMaskDefines.MONSTER_MISSILE.id)
            {
                ProcessPhsysicsType(coll.gameObject, data.physicsType);
            }
            #endregion
        }