Exemplo n.º 1
0
    public void DropItem()
    {
        if (Item != null && PlateNextToPlayer && !PlateNextToPlayer.HasDollInCollision())
        {
            GameObject player        = GameObject.Find("NewPlayer");
            Image      dollImage     = player.transform.Find("PlayerCanvas/Doll").GetComponent <Image>();
            Image      ironDollImage = player.transform.Find("PlayerCanvas/IronDoll").GetComponent <Image>();

            float   plateSize     = PlateNextToPlayer.transform.GetComponent <BoxCollider2D>().size.y *PlateNextToPlayer.transform.localScale.y;
            float   itemSize      = Item.transform.GetComponent <BoxCollider2D>().size.y *Item.transform.localScale.y;
            Vector3 spawnPosition = new Vector3(PlateNextToPlayer.transform.position.x, PlateNextToPlayer.transform.position.y + PlateNextToPlayer.transform.GetComponent <Collider2D>().offset.y + plateSize / 2 + itemSize / 2, 0);

            Instantiate(Item, spawnPosition, Quaternion.identity);
            Item = null;

            dollImage.enabled     = false;
            ironDollImage.enabled = false;
        }
    }