public void OnColliderEnter(SpriteCollider2D other) { if (other.gameObject.CompareTag("Bullet")) { counter.Score += 10; counter.DestroyedEnemies++; effect.PlayEffect(); Destroy(gameObject); } }
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); }
public static void RemoveContainCollidedPair(SpriteCollider2D obj) { var num = 0; CollidedPairs.ForEach(it => { if (it.IsContains(obj)) { num++; } }); Debug.Log($"contains : {num}"); }
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); } }
private static bool IsPairCollided(List <CollidedPair> list, SpriteCollider2D a, SpriteCollider2D b) { return(list.Any(it => it.IsEquals(a, b))); }
private void HandleColliderExit(SpriteCollider2D a, SpriteCollider2D b) { RemoveCollidedPair(a, b); a.onColliderExit.Invoke(b); b.onColliderExit.Invoke(a); }
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); }
public CollidedPair(SpriteCollider2D a, SpriteCollider2D b) { _a = a; _b = b; }
public bool IsContains(SpriteCollider2D obj) { return(_a == obj || _b == obj); }
public bool IsEquals(SpriteCollider2D a, SpriteCollider2D b) { return(_a == a && _b == b || _a == b && _b == a); }