示例#1
0
    public static BoundsExitFlag CheckOutOfBounds(Bounds bounds)
    {
        Rect r = Camera.main.worldSpaceRect();

        BoundsExitFlag exitFlags = BoundsExitFlag.None;

        if (bounds.max.x > (r.xMax + bounds.size.x))
        {
            exitFlags |= BoundsExitFlag.Right;
        }
        else if (bounds.min.x < (r.xMin - bounds.size.x))
        {
            exitFlags |= BoundsExitFlag.Left;
        }

        if (bounds.max.y > (r.yMax + bounds.size.y))
        {
            exitFlags |= BoundsExitFlag.Top;
        }
        else if (bounds.min.y < (r.yMin - bounds.size.y))
        {
            exitFlags |= BoundsExitFlag.Bottom;
        }

        return(exitFlags);
    }
示例#2
0
    public static BoundsExitFlag CheckOutOfBounds(Vector3 position)
    {
        Rect r = Camera.main.worldSpaceRect();

        BoundsExitFlag exitFlags = BoundsExitFlag.None;

        if (position.x > (r.xMax + 1.0))
        {
            exitFlags |= BoundsExitFlag.Right;
        }
        else if (position.x < (r.xMin - 1.0))
        {
            exitFlags |= BoundsExitFlag.Left;
        }

        if (position.y > (r.yMax + 1.0))
        {
            exitFlags |= BoundsExitFlag.Top;
        }
        else if (position.y < (r.yMin - 1.0))
        {
            exitFlags |= BoundsExitFlag.Bottom;
        }

        return(exitFlags);
    }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        BoundsExitFlag flags = GameHelper.CheckOutOfBounds(transform.position);

        if ((flags & BoundsExitFlag.Left) == BoundsExitFlag.Left || (flags & BoundsExitFlag.Right) == BoundsExitFlag.Right)
        {
            Destroy(this);
        }
    }