Exemple #1
0
        public void OnColliderEnter(SpriteCollider2D other)
        {
            if (other.gameObject.CompareTag("Bullet"))
            {
                counter.Score += 10;
                counter.DestroyedEnemies++;

                effect.PlayEffect();
                Destroy(gameObject);
            }
        }
Exemple #2
0
        private void HandleColliding(SpriteCollider2D a, SpriteCollider2D b)
        {
            if (!IsPairCollided(CollidedPairs, a, b))
            {
                a.onColliderEnter.Invoke(b);
                b.onColliderEnter.Invoke(a);

                CollidedPairs.Add(new CollidedPair(a, b));
            }

            a.onColliding.Invoke(b);
            b.onColliding.Invoke(a);
        }
Exemple #3
0
        public static void RemoveContainCollidedPair(SpriteCollider2D obj)
        {
            var num = 0;

            CollidedPairs.ForEach(it =>
            {
                if (it.IsContains(obj))
                {
                    num++;
                }
            });

            Debug.Log($"contains : {num}");
        }
Exemple #4
0
        private void RemoveCollidedPair(SpriteCollider2D a, SpriteCollider2D b)
        {
            CollidedPair target = null;

            foreach (var it in CollidedPairs.Where(it => it.IsEquals(a, b)))
            {
                target = it;
            }

            if (target != null)
            {
                CollidedPairs.Remove(target);
            }
        }
Exemple #5
0
 private static bool IsPairCollided(List <CollidedPair> list, SpriteCollider2D a, SpriteCollider2D b)
 {
     return(list.Any(it => it.IsEquals(a, b)));
 }
Exemple #6
0
 private void HandleColliderExit(SpriteCollider2D a, SpriteCollider2D b)
 {
     RemoveCollidedPair(a, b);
     a.onColliderExit.Invoke(b);
     b.onColliderExit.Invoke(a);
 }
Exemple #7
0
 private static bool IsColliding(SpriteCollider2D a, SpriteCollider2D b)
 {
     return(Math.Abs(a.X - b.X) < a.Width / 2 + b.Width / 2 &&
            Math.Abs(a.Y - b.Y) < a.Height / 2 + b.Height / 2);
 }
Exemple #8
0
 public CollidedPair(SpriteCollider2D a, SpriteCollider2D b)
 {
     _a = a;
     _b = b;
 }
Exemple #9
0
 public bool IsContains(SpriteCollider2D obj)
 {
     return(_a == obj || _b == obj);
 }
Exemple #10
0
 public bool IsEquals(SpriteCollider2D a, SpriteCollider2D b)
 {
     return(_a == a && _b == b || _a == b && _b == a);
 }