コード例 #1
0
        /// <summary>
        /// Check user Bound (EnterAreas) is completely inside the Fence Area
        /// if it's true -> EnableFence
        /// if it's false -> DisableFence
        /// </summary>
        public virtual void OnTriggerStay2D(Collider2D o)
        {
            HitBox h = o.GetComponent <HitBox>();

            Debug.LogFormat("fence hit {0}", h);

            if (h && h.type == HitBoxType.EnterAreas)
            {
                Bounds  b    = h.GetComponent <BoxCollider2D>().bounds;
                Vector2 pmin = b.min;
                Vector2 pmax = b.max;

                // check if the body is completely inside
                if (
                    body.Contains(pmin) &&
                    body.Contains(pmax) &&
                    body.Contains(new Vector2(pmin.x, pmax.y)) &&
                    body.Contains(new Vector2(pmax.x, pmin.y))
                    )
                {
                    EnableFence(h.owner.GetComponent <Character>());
                }
                else
                {
                    DisableFence(h.owner.GetComponent <Character>());
                }
            }
        }