Example #1
0
    /// <summary>
    /// Attempt to switch this container's card to the other container's index
    /// </summary>
    public void SwitchCards(int this_index, GameObject card, GridContainer container, int other_index)
    {
        //Debug.Log("from container " + this.name + " switch " + card.name + " in index " + this_index + " to container " + container.name + " at index " + other_index);
        if (!ValidIndex(this_index))
        {
            return;
        }
        else if (!container.ValidIndex(other_index))
        {
            return;
        }

        GameObject other_card = container.GetCardFromIndex(other_index);

        if (other_card != null) //card exists in other container
        {
            other_card.transform.SetParent(null);
            AddCard(other_card, this_index);
            container.AddCard(card, other_index);
        }
        else
        {
            container.AddCard(card, other_index);
        }
    }