Container.SpillContents C# (CSharp) Method

SpillContents() public method

public SpillContents ( ) : void
return void
    public void SpillContents()
    {
        //Removes the contents of a container out in the real world.
        int counter;
        TileMap tm =GameWorldController.instance.Tilemap; //GameObject.Find("Tilemap").GetComponent<TileMap>();
        GameWorldController.FreezeMovement(this.gameObject);
        ObjectInteraction objInt = this.gameObject.GetComponent<ObjectInteraction>();
        objInt.SetWorldDisplay(objInt.GetEquipDisplay());
        for (int i=0; i<=MaxCapacity ();i++)
        {
            if (GetItemAt (i)!="")
            {
                GameObject Spilled = GameObject.Find (GetItemAt (i));
                if (Spilled!=null)
                {
                    bool flag=false;
                    Vector3 randomPoint=this.transform.position;
                    counter=0;
                    while ((flag==false) && (counter<25))
                    {
                        randomPoint = this.transform.position+Random.insideUnitSphere;
                        if(randomPoint.y<this.transform.position.y)
                        {
                            randomPoint.y=this.transform.position.y+0.1f;
                        }
                        flag = ((!Physics.CheckSphere(randomPoint,0.5f)) && (tm.ValidTile(randomPoint)));
                        counter++;
                    }
                    if (flag==true)
                    {//No object interferes with the spill
                        RemoveItemFromContainer(i);
                        Spilled.transform.position=randomPoint;
                        Spilled.GetComponent<ObjectInteraction>().PickedUp=false;
                        GameWorldController.UnFreezeMovement(Spilled);
                    }
                    else
                    {//No where to put the item. Put it at the containers position.
                        RemoveItemFromContainer(i);
                        Spilled.transform.position=this.transform.position;
                        Spilled.GetComponent<ObjectInteraction>().PickedUp=false;
                        GameWorldController.UnFreezeMovement(Spilled);
                    }
                }
            }
        }
        GameWorldController.UnFreezeMovement(this.gameObject);
    }

Usage Example

Ejemplo n.º 1
0
    void OnDeath()
    {
        Conversation cnv = this.GetComponent <Conversation>();

        if (cnv != null)
        {
            if (cnv.OnDeath() == true)
            {
                return;
            }
        }

        NPC_DEAD = true;
        //Dump items on the floor.
        //
        Container cnt = this.GetComponent <Container>();

        if (cnt != null)
        {
            Debug.Log("Spilling " + this.name);
            cnt.SpillContents();            //Spill contents is still not 100% reliable so don't expect to get all the items you want.
        }
        else
        {
            Debug.Log("no container to spill");
        }
    }