Exemple #1
0
        public void NotifyCollision(Hitbox hitbox, bool isExit = false)
        {
            if (Collisions.Contains(hitbox))
            {
                if (isExit || !CollidesWith(hitbox))
                {
                    Collisions.Remove(hitbox);

                    if (AreaExitSound != null)
                    {
                        SoundManager.Instance.PlayClipAtPoint(AreaExitSound, transform.position);
                    }
                    Collisions.Remove(hitbox);
                    OnAreaExit.Invoke(hitbox);
                    hitbox.NotifyCollisionExit(this);

                    if (Collisions.Count == 0)
                    {
                        enabled = false;
                    }
                }
            }
            else
            {
                if (isExit)
                {
                    return;
                }
                if (!CollidesWith(hitbox))
                {
                    return;
                }

                if (AreaEnterSound != null)
                {
                    SoundManager.Instance.PlayClipAtPoint(AreaEnterSound, transform.position);
                }
                Collisions.Add(hitbox);
                OnAreaEnter.Invoke(hitbox);
                hitbox.NotifyCollisionEnter(this);

                if (Collisions.Count == 1)
                {
                    enabled = true;
                }
            }
        }
Exemple #2
0
        public void FixedUpdate()
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return;
            }
#endif

            if (Collisions.Count == 0)
            {
                enabled = false;
                return;
            }

            foreach (var hitbox in Collisions)
            {
                OnAreaStay.Invoke(hitbox);
                hitbox.NotifyCollisionStay(this);
            }
        }