void Update()
 {
     if (Discard == null && MyController.Game != null)
     {
         Discard = MyController.Game.DiscardPile;
     }
 }
    public void OnCardClicked()
    {
        // Only visible cards that have more than 1 as their amount can be clicked.

        if (!visible || !enabled)
        {
            return;
        }

        Debug.Log("Card " + unitCode + " clicked!");

        // Construction cards -- Available only if the player is in the build phase.
        if (IsConstructionCard())
        {
            if (inventory.GetPlayer().GetPhase() == GamePlayer.Phase.TRADE_BUILD_IDLE)
            {
                // Select
                Debug.Log("Selecting " + unitCode);
                DisplaySelectedCard();
                inventory.GetPlayer().SetPhase(GamePlayer.Phase.BUILDING);
                inventory.GetPlayer().SetSelectedConstructionCard(this);
            }
            else if (inventory.GetPlayer().GetPhase() == GamePlayer.Phase.BUILDING)
            {
                // If I am the selected card -- deselect. Otherwise, deselect other card and select this card.
                if (inventory.GetPlayer().GetSelectedConstructionCard() == this)
                {
                    // Deselect
                    Debug.Log("Deselecting " + unitCode);
                    DisplayNormalCard();
                    inventory.GetPlayer().SetPhase(GamePlayer.Phase.STOP_BUILDING);
                }
                else
                {
                    Debug.Log("Switching selection to: " + unitCode);
                    DisplaySelectedCard();

                    Card previousSelectedCard = inventory.GetPlayer().GetSelectedConstructionCard();

                    previousSelectedCard.DisplayNormalCard();

                    inventory.GetPlayer().TurnOffIndicators();

                    inventory.GetPlayer().SetSelectedConstructionCard(this);
                }
            }
        }


        // Resource cards -- Clicking on these is possible if the player is currently trading or discarding their hand.

        if (IsResourceCard())
        {
            TradeController   tradeController   = GameObject.Find("TradeController").GetComponent <TradeController>();
            DiscardController discardController = GameObject.Find("DiscardController").GetComponent <DiscardController>();

            // Check if it's in the inventory or in the trade slot.
            if (gameObject.tag == "InventoryCard")
            {
                if (tradeController.IsTrading() && !tradeController.IsYearOfPlenty())
                {
                    // Move 1 stock from the inventory to the local offers slot if the player isn't playing a Year of Plenty card.
                    inventory.TakeFromPlayer(this.unitCode, 1);
                    tradeController.OfferResource(this.unitCode, 1);
                }
                else if (discardController.IsDiscarding())
                {
                    // Move 1 stock from the inventory to the discard slot.
                    inventory.TakeFromPlayer(this.unitCode, 1);
                    discardController.DiscardResource(this.unitCode, 1);
                }
            }
            else if (gameObject.tag == "TradeCard")
            {
                // if it's the remote player card that's being clicked, do not do anything
                if (tradeController.IsLocalCard(this))
                {
                    // Move 1 stock from the offers panel to the inventory.

                    inventory.GiveToPlayer(this.unitCode, 1);
                    tradeController.RetractResourceOffer(this.unitCode, 1);
                }
                else
                {
                    // If the player is trading with the supply, handle the click.
                    if (tradeController.IsSupplyTrading())
                    {
                        tradeController.SupplyCardChosen(this.unitCode, 1);
                    }
                    else if (tradeController.IsYearOfPlenty())
                    {
                        tradeController.YearOfPlentyCardChosen(this.unitCode, 1);
                    }
                }
            }
            else if (gameObject.tag == "DiscardCard")
            {
                // Move 1 stock from the discard panel to the inventory.

                inventory.GiveToPlayer(this.unitCode, 1);
                discardController.RetractResourceDiscard(this.unitCode, 1);
            }
            else if (gameObject.tag == "MonopolyCard")
            {
                // Initialise stealing of this resource type from all the other players.

                discardController.MonopolyCardClicked(this.unitCode);
            }
        }

        // Development cards -- If they're available this turn, prompt the player to confirm whether or not to play them.

        if (IsDevelopmentCard())
        {
            // A victory card cannot be played.
            if (unitCode == Inventory.UnitCode.VICTORY_CARD)
            {
                return;
            }

            // If it is not this player's turn, disable development card usage.
            if (inventory.GetPlayer().IsMyTurn() == false)
            {
                return;
            }

            // If the player is not in the IDLE phase, return.

            if (inventory.GetPlayer().GetPhase() != GamePlayer.Phase.TRADE_BUILD_IDLE)
            {
                return;
            }

            // Show the play development card confirmation panel.
            GameObject.Find("ShopController").GetComponent <ShopController>().PlayDevelopmentCard(this.unitCode);
        }
    }