Container.GetWeight C# (CSharp) Method

GetWeight() public method

public GetWeight ( ) : float
return float
    public override float GetWeight()
    {
        //Get the weight of all items in the container
        float answer=base.GetWeight();//The container has it's own weight as well.
        for (int i=0; i<=MaxCapacity();i++)
        {
            if (GetItemAt(i)!="")
            {
                GameObject ItemAt = GameObject.Find (GetItemAt(i));
                if (ItemAt!=null)
                {
                    ObjectInteraction objContainerItem = ItemAt.GetComponent<ObjectInteraction>();
                    if (objContainerItem!=null)
                    {
                        answer+=objContainerItem.GetWeight();
                    }
                }
            }
        }
        return answer;
    }

Usage Example

Ejemplo n.º 1
0
        private bool CheckWeight(Container container, int width, int depth, int z)
        {
            int weight;

            for (int i = 0; i < ship.GetHeight(); i++)
            {
                weight = container.GetWeight();
                for (int height = i; height < ship.GetHeight(); height++)
                {
                    if (ship.GetContainer(width, depth, height) != null)
                    {
                        weight += ship.GetContainer(width, depth, height).GetWeight();
                    }
                }

                if (ship.GetContainer(width, depth, i) != null)
                {
                    weight -= ship.GetContainer(width, depth, i).GetWeight();
                }

                if (weight > 120)
                {
                    return(false);
                }

                weight = 0;
            }

            return(true);
        }
All Usage Examples Of Container::GetWeight