// This is when the player clicks the spawner
 void OnMouseDown()
 {
     if (isAvocado)
     {
         // We check if the player has any avocados
         if (playerInventory.playerAvocado > 0)
         {
             playerInventory.AddAvocado(-1);                                                   // This takes an avocado off the player
             GameObject avocado = Instantiate(spawn, transform.position, Quaternion.identity); // We create an avocado
             avocado.GetComponent <pickup_script>().OnMouseDown();                             // We tell the avocado we want to pick it up
             avocado.transform.SetParent(parentObject);                                        // We attach the item to the parent
         }
     }
     else if (isBread)
     {
         // We check if the player has any bread
         if (playerInventory.playerBread > 0)
         {
             playerInventory.AddBread(-1);                                                   // We take a piece of bread off the player
             GameObject bread = Instantiate(spawn, transform.position, Quaternion.identity); // We create some bread
             bread.GetComponent <pickup_script>().OnMouseDown();                             // We tell the bread we want to pick it up
             bread.transform.SetParent(parentObject);                                        // We attach the item to the parent
         }
     }
     else
     {
         GameObject item = Instantiate(spawn, transform.position, Quaternion.identity); // We create the item
         item.GetComponent <pickup_script>().OnMouseDown();                             // We tell the item we want to pick it up
         item.transform.SetParent(parentObject);                                        // We attach the item to the parent
     }
 }
Beispiel #2
0
    void OnMouseDown()
    {
        // We check if the player can afford the item
        if (playerInventory.playerMoney >= price)
        {
            // We take money off the player
            playerInventory.AddMoney(-price);

            // We check if the player is buying an avocado
            if (isAvocado)
            {
                // We give the player an avocado
                playerInventory.AddAvocado(1);
            }
            // We check to see if the player is trying to buy
            else if (isBread)
            {
                // We give the player some bread
                playerInventory.AddBread(1);
            }
        }
    }