コード例 #1
0
ファイル: Shop.cs プロジェクト: bigfootledur/JeuVideoUnity
    public void SellObject(CollectableObject objectToSell)
    {
        WalkingUnit buyer = TriggerShop.GetNearestOne();

        if (buyer == null)
        {
            print("Nobody is near");
            return;
        }

        if (!buyer.faction.Equals(GameMaster.PlayerFaction))
        {
            return;
        }

        if (buyer)
        {
            if (buyer && buyer.HasInventory() &&
                (buyer.faction.Equals(Faction.Blue) && (gameMaster.BlueWool >= objectToSell.MoneyCost)) ||
                (buyer.faction.Equals(Faction.Red) && (gameMaster.RedWool >= objectToSell.MoneyCost)))
            {
                bool objectSold = false;
                for (int i = 0; i < buyer.Inventory.Length; i++)
                {
                    if (buyer.Inventory[i] == null)
                    {
                        if (buyer.faction.Equals(Faction.Blue) && (gameMaster.BlueWool >= objectToSell.MoneyCost))
                        {
                            gameMaster.BlueWool -= objectToSell.MoneyCost;
                        }
                        else if (buyer.faction.Equals(Faction.Red) && (gameMaster.RedWool >= objectToSell.MoneyCost))
                        {
                            gameMaster.RedWool -= objectToSell.MoneyCost;
                        }
                        else
                        {
                            Debug.LogError("Couldn't take money from red/blue wool when selling " + objectToSell + " to " + buyer.gameObject);
                        }

                        CollectableObject obj = Instantiate(objectToSell);
                        obj.gameObject.SetActive(false);
                        buyer.TakeObject(obj);
                        objectSold = true;
                        break;
                    }
                }
                if (!objectSold)
                {
                    print("Inventory full");
                }
            }
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (objectToTake)
        {
            if (moveScript.RemainingDistance() <= 15 && moveScript.RemainingDistance() > 0.01f)
            {
                self.TakeObject(objectToTake);
                StopAction();
            }
        }

        else if (targetPosition != Vector3.zero)
        {
            if (moveScript.RemainingDistance() <= 15 && moveScript.RemainingDistance() > 0.01f)
            {
                self.DropObject(objectToDrop, targetPosition);
                StopAction();
            }
        }
    }