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);
}