Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kobohdashi · Aug 24, 2013 at 11:10 PM · javascriptinventoryfunctionspick up

Using items from inventory

Hello all my game is coming along great thanks to all the help from everyone in the community i am here again to ask for some guidance I downloaded the free inventory system that Brackeys made available for free https://www.assetstore.unity3d.com/#/content/10384 I got it into my game its working the only thing is that when I use say the water to replenish the thirst bar the hunger bar and energy bar also go up, and I only want to affect the thirst bar when I use the water here is the script

 #pragma strict
 
 //This script allows you to insert code when the Item is used (clicked on in the inventory).
 
 var deleteOnUse = true;
 
 private var playersInv : Inventory;
 private var item : Item;
 
 @script AddComponentMenu ("Inventory/Items/Item Effect")
 @script RequireComponent(Item)
 
 //This is where we find the components we need
 function Awake ()
 {
     playersInv = FindObjectOfType(Inventory); //finding the players inv.
     if (playersInv == null)
     {
         Debug.LogWarning("No 'Inventory' found in game. The Item " + transform.name + " has been disabled for pickup (canGet = false).");
     }
     item = GetComponent(Item);
 }
 
 //This is called when the object should be used.
 function UseEffect () 
 {
     Thirst.tcurHP += 25;
     Hunger.curHP += 25;
     
     //Play a sound
     playersInv.gameObject.SendMessage("PlayDropItemSound", SendMessageOptions.DontRequireReceiver);
     
     //This will delete the item on use or remove 1 from the stack (if stackable).
     if (deleteOnUse == true)
     {
         DeleteUsedItem();
     }
 }
 
 //This takes care of deletion
 function DeleteUsedItem()
 {
     if (item.stack == 1) //Remove item
     {
         playersInv.RemoveItem(this.gameObject.transform);
     }
     else //Remove from stack
     {
         item.stack -= 1;
     }
     Debug.Log(item.name + " has been deleted on use");
 }

the problem starts at line 25 where I added the function to be able to use the pick ups any help on how to repair this will be greatly appreciated have a great weekend and happy game making. -K

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Aug 25, 2013 at 01:00 AM 0
Share

In your game, what does this line do: Hunger.curHP += 25; Since Energy isn't mentioned at all in this script, is it perhaps tied to hunger in another script?

avatar image Kobohdashi · Aug 25, 2013 at 01:09 AM 0
Share

hello that is the line I put in to replenish the hunger, hunger is the script and curHP is the current hunger points, the 25 is the how much to add, the same with thirst.tcurHP+=25 its to replenish the thirst bar, but what is happening it does not matter witch one I use all the progress bars get filled, and I only want the water to affect the thirst bar and the food the hunger bar and so on...

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by getyour411 · Aug 25, 2013 at 01:12 AM

In UseEffect() you increase both without anything that would filter (i.e if/then, boolean etc) which to increase. I can only guess that Energy is tied to Hunger and eating gives you an energy boost since there's nothing else here that would affect Energy that I see.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kobohdashi · Aug 25, 2013 at 05:21 AM 0
Share

@getyour411 I removed the energy.ecurHP+=25 and I think I understand about the boolean now I have to learn how to add them if you can point me to a reference or a tutorial to get me up to speed. $$anonymous$$uchas gracias

avatar image Therian13 · Nov 30, 2013 at 07:12 AM 0
Share

did you ever figure this out? im having the same issue and cannot get it to work....

avatar image BillyJazz · Apr 09, 2014 at 09:00 PM 0
Share

Anyone get anywhere with this by now? I'm having the same problem, want multiple effects but only the ability for one effect

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Pick up ability? And inventory? 1 Answer

how to pick up items and add them to inventory 0 Answers

My script for pick up items work is wrong! Help please 1 Answer

HELP Adventure Loot System 1 Answer

error CS1526: A new expression requires () or [] after type 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges