/**
     * <summary>
     * Watch for the item on top of the belt
     * </summary>
     */
    protected override void WatchForItem()
    {
        Bounds  bounds = this.transform.GetComponent <Collider2D>().bounds;
        Vector2 size   = bounds.size;

        Collider2D[] colliders = Physics2D.OverlapBoxAll(this.transform.position, size, 0);
        foreach (Collider2D collider in colliders)
        {
            if (collider.tag == Tags.Item)
            {
                Transform item       = collider.GetComponent <Transform>();
                Bounds    itemBounds = item.GetComponent <Collider2D>().bounds;
                Vector2   itemPoint  = new Vector2(itemBounds.min.x, itemBounds.max.y);

                // Always move when the item is exactly or more on top of the collider
                if (!bounds.Contains(itemPoint))
                {
                    continue;
                }

                ItemBehaviour itemBehaviour = item.GetComponent <ItemBehaviour>();
                itemBehaviour.direction = ItemDirection.Right;
                itemBehaviour.speed     = 5f;
                itemBehaviour.MoveRight();
            }
        }
    }
    /**
     * <summary>
     * Watch for the item on top of the belt
     * </summary>
     */
    protected override void WatchForItem()
    {
        Bounds  bounds = this.transform.GetComponent <Collider2D>().bounds;
        Vector2 size   = bounds.size;

        Collider2D[] colliders = Physics2D.OverlapBoxAll(this.transform.position, size, 0);
        foreach (Collider2D collider in colliders)
        {
            if (collider.tag == Tags.Item)
            {
                Transform     item          = collider.GetComponent <Transform>();
                ItemBehaviour itemBehaviour = item.GetComponent <ItemBehaviour>();

                Bounds  itemBounds = item.GetComponent <Collider2D>().bounds;
                Vector2 itemPoint  = new Vector2(itemBounds.min.x, itemBounds.max.y);

                // Always move when the item is exactly or more on top of the collider
                if (!bounds.Contains(itemPoint))
                {
                    continue;
                }

                // Determine the direction of the item it is moving.
                // If the item is heading up and it has not reached the origin point. Keep moving up.
                if (itemBehaviour.direction == ItemDirection.Up && item.position.y < this.transform.position.y)
                {
                    itemBehaviour.direction = ItemDirection.Up;
                    itemBehaviour.speed     = 5f;
                    itemBehaviour.MoveUp();
                }
                // If the item is heading down and it has not reached the origin point. Keep moving down.
                else if (itemBehaviour.direction == ItemDirection.Down && item.position.y > this.transform.position.y)
                {
                    itemBehaviour.direction = ItemDirection.Down;
                    itemBehaviour.speed     = 5f;
                    itemBehaviour.MoveDown();
                }
                // Move right
                else
                {
                    itemBehaviour.direction = ItemDirection.Right;
                    itemBehaviour.speed     = 5f;
                    itemBehaviour.MoveRight();
                }
            }
        }
    }
Ejemplo n.º 3
0
    /**
     * <summary>
     * Watch for the item on top of the belt
     * </summary>
     */
    protected override void WatchForItem()
    {
        Bounds  bounds = this.transform.GetComponent <Collider2D>().bounds;
        Vector2 size   = bounds.size;

        Collider2D[] colliders = Physics2D.OverlapBoxAll(this.transform.position, size, 0);
        foreach (Collider2D collider in colliders)
        {
            if (collider.tag == Tags.Item)
            {
                Transform     item          = collider.GetComponent <Transform>();
                ItemBehaviour itemBehaviour = item.GetComponent <ItemBehaviour>();
                Bounds        itemBounds    = item.GetComponent <Collider2D>().bounds;
                Vector2       itemPoint     = new Vector2(itemBounds.max.x, itemBounds.min.y);

                // Do not move the item if the item point is not on the belt
                if (!bounds.Contains(itemPoint))
                {
                    continue;
                }

                // Determine the direction of the item it is moving.
                // If the item is heading right and it has not reached the origin point. Keep moving right.
                if (itemBehaviour.direction == ItemDirection.Right && item.position.x < this.transform.position.x)
                {
                    itemBehaviour.direction = ItemDirection.Right;
                    itemBehaviour.speed     = 5f;
                    itemBehaviour.MoveRight();
                }
                // If the item is heading left and it has not reached the origin point. Keep moving left.
                else if (itemBehaviour.direction == ItemDirection.Left && item.position.x > this.transform.position.x)
                {
                    itemBehaviour.direction = ItemDirection.Left;
                    itemBehaviour.speed     = 5f;
                    itemBehaviour.MoveLeft();
                }
                // Move up
                else
                {
                    itemBehaviour.direction = ItemDirection.Up;
                    itemBehaviour.speed     = 5f;
                    itemBehaviour.MoveUp();
                }
            }
        }
    }
Ejemplo n.º 4
0
    /**
     * <summary>
     * Watch for the item on top of the belt
     * Move the items to the origin point then move it downward
     * </summary>
     */
    protected override void WatchForItem()
    {
        Bounds  bounds = this.transform.GetComponent <Collider2D>().bounds;
        Vector2 size   = bounds.size;

        Collider2D[] colliders = Physics2D.OverlapBoxAll(this.transform.position, size, 0);
        foreach (Collider2D collider in colliders)
        {
            if (collider.tag == Tags.Item)
            {
                Transform item       = collider.GetComponent <Transform>();
                Bounds    itemBounds = item.GetComponent <Collider2D>().bounds;
                Vector2   itemPoint  = new Vector2(itemBounds.min.x, itemBounds.min.y);

                // Do not move the item if the item point is not on the belt
                if (!bounds.Contains(itemPoint))
                {
                    continue;
                }

                // Has the item reached the origin point?
                if (item.position.x < this.transform.position.x)
                {
                    ItemBehaviour itemBehaviour = item.GetComponent <ItemBehaviour>();
                    itemBehaviour.direction = ItemDirection.Right;
                    itemBehaviour.speed     = 5f;
                    itemBehaviour.MoveRight();
                }
                // If the item has reached the origin point, move up
                else
                {
                    ItemBehaviour itemBehaviour = item.GetComponent <ItemBehaviour>();
                    itemBehaviour.direction = ItemDirection.Up;
                    itemBehaviour.speed     = 5f;
                    itemBehaviour.MoveUp();
                }
            }
        }
    }