Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

S-Inventory: Equipment, Crafting, Skill Bar, Item Groups, Containers & Merchant (C# & JS)

Discussion in 'Assets and Asset Store' started by OussamaB, Jul 29, 2013.

Thread Status:
Not open for further replies.
  1. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    I like this whole ghosted recipes idea! Thank you. One other thing, should I leave that recipe menu at the left of the crafting menu (see the last screenshots that I've posted) or just make an option to turn it on or off as well?
     
  2. cg_destro

    cg_destro

    Joined:
    Aug 13, 2013
    Posts:
    142
    the more modular and flexible system the better :)
    I would love to see option to pick scroll/ blueprint from inventory and recipe ingredients show up ghosted on crafting table, or option to turn on and off list of all possible and/ or all unlocked/ successful created items, or like I write earlier picking items with zero quantity from inventory :)
    list could be there as an options with sorting by category, value or any attribute creator can imagine :)
    and with ability to switch list into tiled icons of crafting items, most people much, much faster reads images than words :) but list could be more helpful when you have 50+ recipes and want quickly find Warhammer lvl12 :)
    and ghsoted function would work much better than list of items like in yous screeshot :) or another option to expand recipe and show image of items and placement on crafting table without ghosting, little harder version of crafting :)
    I should probably stop with all this ideas now, should be enough :p
     
  3. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    That's awesome. I'm definitely going to add your suggestions but It's going to take more time xD
     
    Last edited: Jul 31, 2014
  4. cg_destro

    cg_destro

    Joined:
    Aug 13, 2013
    Posts:
    142
  5. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    Hello there. I just wanted to let you know that I've broken my left ankle while playing football and had to wear a cast. I'm not staying for few days because I can't take care of myself in this state. I promise you that I'll continue working on the crafting system as soon as the pain goes away and I have access to my PC again. Thanks for your patience.
     
  6. cg_destro

    cg_destro

    Joined:
    Aug 13, 2013
    Posts:
    142
    sorry to hear that, don't worry about crafting and get better first :)
     
  7. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    Thank you for your patience. I've already noted everything I need to do so that it will be faster to code as soon as I have access to my computer again.
     
  8. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    I'm close to finish the crafting system and I decided to include it in S-Inventory along with the other features. I will keep the same price of course.
     
  9. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    Here's a new screenshot of the crafting window. All the features that are planned for the next update has been added and more will come in future updates. I will submit the update as soon as I finish the custom inspector for the craft manager.

     
  10. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    Hello everyone, I have submitted the update that includes the crafting system to the asset store. I have also updated the documentation: http://soumidelrio.com/document/s-inventory/crafting/

    The next update will mainly include custom inspector view for each system and improvements on the crafting system based on your suggestions.
     
  11. ZodiaX Corp

    ZodiaX Corp

    Joined:
    May 17, 2013
    Posts:
    5
    Hello i have just bought your Unity pack and the first thing that popped up were 4 errors

    //Assets/S-Inventory/JS/Scripts/CraftManager.js(389,159): BCE0019: 'ShortDescription' is not a member of //'UnityEngine.Component'.

    //Assets/S-Inventory/JS/Scripts/CraftManager.js(389,136): BCE0019: 'Name' is not a member of '//UnityEngine.Component'.

    //Assets/S-Inventory/JS/Scripts/CraftManager.js(388,127): BCE0019: 'ItemIcon' is not a member of //'UnityEngine.Component'.

    //Assets/S-Inventory/JS/Scripts/CraftManager.js(382,66): BCE0019: 'Name' is not a member of //'UnityEngine.Component'.

    Why did these pop up? Thanks

    Android Build
     
    Last edited: Sep 15, 2014
  12. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    Hello, you just need to go to line 358 in the craft manager script and replace it with this:
    "var ResultScript : Item = Recipes[RecipeID].Result.gameObject.GetComponent("Item");"
    But please keep in mind that some features don't work on mobile platforms currently.
     
  13. goldencruz

    goldencruz

    Joined:
    Oct 2, 2013
    Posts:
    94
    with your kit can I change the interface and if so is there some docs about how to.
     
  14. ZodiaXCorpX

    ZodiaXCorpX

    Joined:
    Sep 16, 2014
    Posts:
    5
    Thank you! wow you really are as responsive as they have said, expect my future purchases!
    -ZodiaXCorpX
     
  15. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    You can actually change everything about how the look of the interface. You can change the textures, each size of texture, etc.. You can also choose to hide parts of the interface and keep other parts. If you are looking for a whole modification for the menus GUI, then I'll be more than glad to modify the code to suit your needs.
    Anyways, here's the full guide link can be found in the main post. My website seems to be down right now. It should be back up soon as I'm trying to figure out the problem with the host provider.

    Glad I could help you! Looking forward to your suggestions for future updates!
     
  16. dreamlarp

    dreamlarp

    Joined:
    Apr 22, 2011
    Posts:
    854
    What method do you use for saving/loading? I have read through your doc but can't find this out.
     
  17. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    Currently, saving and loading is done by player prefs. Might change it to a database in the future.
     
    RealSoftGames likes this.
  18. dreamlarp

    dreamlarp

    Joined:
    Apr 22, 2011
    Posts:
    854
    You should. Payer prefab is why I will not buy it.
     
  19. RealSoftGames

    RealSoftGames

    Joined:
    Jun 8, 2014
    Posts:
    220
    Hi just a quick question but how easily could this be implemented with Realistic FPS Prefab, if this can integrate correctly and can be done following some Instructional Tutorial or documentation to get them both working together i will purchase this and rate 5 star =)
     
  20. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    Actually, people find it much easier to convert player prefs to their own saving and loading system. Some of them don't want to use database for that. That's why I'm using the default unity saving and loading system.


    It should work without any problem with Realistic FPS prefab. Here's one of the asset's review:
    "
    Works well with Realistic FPS

    I've built a mobile survival game with Realistic FPS and it was time to add an inventory system. This fits in well and the developer is very polite and helpful. I highly recommend this for anyone in need of an inventory system and doesn't want or have the time to build their own."
     
  21. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,266
    Maybe it is only in the demo but put back button do not work if i decide to not sell i.e. the sword.
    So when i close the window with finish i loose a sword but get the money.
    Also i can nopt equip, and put things into the craft and bottom bar.

    Then i hope to see an update for unity´s new ui for this and the s-quest asset.
    I think i can use them together without a problem?

    Oh and what it the hand in the left bottom corner for?

    Edit:
    Just tried it in fullscrenn with the right mouse button and then i can equip but thought i just can drag and drop them too because that i would do on mobile or even on the pc normaly.
     
    Last edited: Sep 19, 2014
  22. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    It actually works, you need to select the item that you want to take back and then click on the "take back" button. Clicking on "Finished" sells your items indeed. There is a "Sell" button to use when you want to sell the items that appears in the vendor list and continue using the vendor's menu (buy something for example). "Finished" button is used like the "Sell" button but closes the vendor menu instead.

    It seems like the drag and drop to the skill bar and equipment menu is not working in the demo, that's really weird. I'll fix ASAP. Thank you for reporting this bug.

    Whenever Unity releases, officially, the new UI system, I'll convert all my assets to support it.

    The left corner button is used to pick up items instead of using the mouse or a keyboard/joystick button. It can be easily disabled from the inspector.
     
  23. RealSoftGames

    RealSoftGames

    Joined:
    Jun 8, 2014
    Posts:
    220

    its great to hear that it works, but im not a full time Coder nor am i a pro at it i can do simple basic editing, but i wouldnt know where to start with a system like this as i have never worked with GUI before, would you have a link to a tutorial to follow how this person had done this, working with Realistic FPS Prefab?
     
  24. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    I'm afraid I don't have his contact info. What are you exactly aiming to do by linking Realistic FPS with S-Inventory? I might be able to help.
     
  25. RealSoftGames

    RealSoftGames

    Joined:
    Jun 8, 2014
    Posts:
    220

    all i wanted to do was use the already active Inventory system created by the Developer at Realistic FPS, Amo system Weapon System ETC, but really looking at, instead of picking up the ammo and using it, storing it in a bag instead, same as potions and other weapons currently set to max holding 2 at a time, i wnat ot be able ot run around my game and colelct as much loot as possible and go back to my base and drop it all off in a Chest for example more or less a safe, also not to fussed about having a character equipment, not looking at adding stats, its more of a Simulator so stats wont be necessary unless its a weapon, but saying so the amo, because its a multilayer game, to be able to drop it for other Players to pick up (Friends for example that you are playing with) to me it seems like what has already been made here + More, mainly the integration with RFPS pickup system to store the items in the bag instead of on the character itself if you know what i mean.
     
  26. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    It seems like a simple code modification for me. I would love to help you with this but unfortunately, I have no experience with Realistic FPS Prefab. Anyway, You should take some time and learn how to code, you will need to code a lot of things yourself no matter how many assets you have.
     
  27. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    Dragging and dropping items on the web player demo has been fixed.
     
  28. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    Working on update that will make S-Quest and S-Inventory even more compatible: You can now see the reward item you'll get by completing the quest. You can hover your mouse cursor over it and see a brief description of it.

    Here's a screenshots:
     
  29. Oldnag

    Oldnag

    Joined:
    Aug 27, 2014
    Posts:
    22
    hi i recently purchaced this and its awesome, are you planning on adding a bank system or containers etc like boxes u can store stuff in?
     
  30. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    Thank you for this great suggestion. This will be included in the next update.
     
  31. yummybrainz

    yummybrainz

    Joined:
    Jan 14, 2014
    Posts:
    65
    Hey Jake,

    It was me that implemented this with the realistic for prefab. Feel free to pm me or we can continue the dialogue here so others can see it as well.

    There is quite of lot of code you need to understand to get it to work. That will be a good refresher for me though and a good learning experience for you ;)

    I'm just about to jump back into that game that uses it (been busy updating another popular game I made with rfps). It will be cool to check out the new crafting system as well.
     
  32. RealSoftGames

    RealSoftGames

    Joined:
    Jun 8, 2014
    Posts:
    220
    i think this would be great for others to see as well as it has been a daunting task for me alone and a very expensive one as well to get it to work, i would recall at least spending in the high hundreds buying assets that just simply do not work together after finding tutes that say they do, others and my self would greatly appreciate if you could share with us here instead of a PM, but it is really up to you if you would love to help out. i personally would love to get this asset or at least one working.
     
  33. yummybrainz

    yummybrainz

    Joined:
    Jan 14, 2014
    Posts:
    65
    Usually you can get 90% of assets to work together without much issue. There are major differences in how a lot of people code though so sometimes it take a little more effort.

    I'm going to create a new empty project with updated assets of both RFPS and S-Inventory. Once I get something up and running I will share the code and setup process here ;)
     
  34. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    That's great. Thanks for your help.
     
  35. dreamlarp

    dreamlarp

    Joined:
    Apr 22, 2011
    Posts:
    854
    What many developers have started doing witch is long overdo is make third party support for the major kits in Unity. Like take a look at the Dialog system. He was one of the first to make support for almost every other kit.

    @SoumiDelRio
    I would first suggest that you contact him and have him add you to his list. Doing so would open you up to a huge amount of people who are using his kit. Second you could start doing some of this yourself. There are many major kits that do not have the systems you provide and that also would open you up to the users of those kits.

    We all need to work to make Unity a much more modular system.
     
  36. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    Sounds like a good idea, I might start doing that for both S-Quest and S-Inventory.
     
  37. dreamlarp

    dreamlarp

    Joined:
    Apr 22, 2011
    Posts:
    854
    I would make sure TonyLi puts you in the Dialog system list first. Then just off the top of my head start with the FPS kits. Those would benefit the most from your app's and would have the most amount of sales for you.
     
  38. yummybrainz

    yummybrainz

    Joined:
    Jan 14, 2014
    Posts:
    65
    Ok so this is slowly coming back to me now :)

    The first place to start with implementation are with the Items. Both S-Inventory and RFPS have their own methods for picking up items. They will work together if you set things up right.

    Firstly place an Object on your stage, for example an ammo object from rfps. Then add the Item component to the ammo like below. Be sure to uncheck the Remove on Pickup option! S-Inventory is already going to remove it so there is no need and you will get null errors if you do not.



    Now we need to edit some scripts. Start with the AmmoPickup.cs located on the object. You need to add a reference to the Inventory Manager you have placed on the stage.

    Code (CSharp):
    1. //REFERENCE TO S-INVETORY :
    2.     [HideInInspector]
    3.     public InventoryManager InvManager;
    4.  
    5.     void Start (){
    6. // ADDED THIS LINE BELOW
    7.         InvManager = FindObjectOfType(typeof(InventoryManager)) as InventoryManager; //Get the Inventory Manager object/script.
    8.  
    9.         myTransform = transform;//manually set transform for efficiency
    10.         weaponObj = Camera.main.transform.GetComponent<CameraKick>().weaponObj;
    11.         //find the PlayerWeapons script in the FPS Prefab to access weaponOrder array
    12.         PlayerWeapons PlayerWeaponsComponent = weaponObj.GetComponentInChildren<PlayerWeapons>();
    13.  
    14.         //scan the children of the FPS Weapons object (PlayerWeapon's weaponOrder array) and assign this item's weaponObj to the
    15.         //weapon object whose weaponNumber in its WeaponBehavior script matches this item's weapon number
    16.         for (int i = 0; i < PlayerWeaponsComponent.weaponOrder.Length; i++)    {
    17.             if(PlayerWeaponsComponent.weaponOrder[i].GetComponent<WeaponBehavior>().weaponNumber == weaponNumber){
    18.                 weaponObj = PlayerWeaponsComponent.weaponOrder[i];
    19.                 break;
    20.             }
    21.         }
    22.     }
    Now find the PickUpItem function and place this add line below the play sound. This will ensure that you hear the sounds on pickup from RFPS. The AddItem is all you need to do to get S-Inventory to place the item in your inventory! Because we are still using the AmmoPickup script RFPS also recognizes that you have more ammo.

    Code (CSharp):
    1. //play pickup sound
    2.             if(pickupSound){AudioSource.PlayClipAtPoint(pickupSound, myTransform.position, 0.75f);}
    3.             //ADD ITEM TO INVENTORY
    4.             InvManager.AddItem(myTransform);
    Now we will need to open the InventoryManager.cs script. Find the AddItem function and look for this code below.

    Code (CSharp):
    1. Item.transform.renderer.enabled = false;
    Replace that line with this check which will remove errors you would receive if the pickup object is located inside a container which most of them are.

    Code (CSharp):
    1. // Adding the below code to remove errors for container objects.
    2.                     if(Item.transform.renderer !=null)
    3.                     {
    4.                         Item.transform.renderer.enabled = false;
    5.                     }
    You can see below I have added the AK47 ammo, a health kit, and an AK47 rifle.

     
    Last edited: Sep 28, 2014
    RealSoftGames likes this.
  39. yummybrainz

    yummybrainz

    Joined:
    Jan 14, 2014
    Posts:
    65
    For weapon pickups you do the exact same as above but this time edit the WeaponPickup.cs file.

    I'm adding the item to the invetory from the removePickup function. That way we still get the sounds from RFPS if we have edited them on the objects ;)

    Code (CSharp):
    1. void RemovePickup (){
    2.        
    3.         //play pickup sound
    4.         if(pickupSound){AudioSource.PlayClipAtPoint(pickupSound, myTransform.position, 0.75f);}
    5.         InvManager.AddItem(myTransform);
    6.  
    7.         if(removeOnUse){
    8.             //remove this weapon pickup from the scene
    9.             Object.Destroy(gameObject);
    10.         }
    11.        
    12.     }
     
  40. yummybrainz

    yummybrainz

    Joined:
    Jan 14, 2014
    Posts:
    65
    For the health pickup do the same as above and edit HealthPickup.cs script.

    I'm adding a public boolean to the object which tells us whether on not we want to auto heal. Then use that inside PickUpItem like below. In this case if we auto heal RFPS does the handling of the object and reversely S-Inventory if we want to add the item to the inventory.

    Code (CSharp):
    1. //script for health pickup items
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class HealthPickup : MonoBehaviour {
    6.     private GameObject playerObj;
    7.     private Transform myTransform;
    8.    
    9.     public float healthToAdd = 25.0f;
    10.     public bool removeOnUse = true;//Does this pickup disappear when used/activated by player?
    11.    
    12.     public AudioClip pickupSound;//sound to playe when picking up this item
    13.     public AudioClip fullSound;//sound to play when health is full
    14.    
    15.     public Texture2D healthPickupReticle;//the texture used for the pick up crosshair
    16.     //Other scripts:
    17.     public bool autoHeal = false;
    18.     [HideInInspector]
    19.     public InventoryManager InvManager;
    20.    
    21.     void Start (){
    22.         InvManager = FindObjectOfType(typeof(InventoryManager)) as InventoryManager; //Get the Inventory Manager object/script.
    23.  
    24.         myTransform = transform;//manually set transform for efficiency
    25.         //assign this item's playerObj value
    26.         playerObj = Camera.main.transform.GetComponent<CameraKick>().playerObj;
    27.     }
    28.    
    29.     void PickUpItem (){
    30.     FPSPlayer FPSPlayerComponent = playerObj.GetComponent<FPSPlayer>();
    31.    
    32.         if (autoHeal) {
    33.                         if (FPSPlayerComponent.hitPoints < FPSPlayerComponent.maximumHitPoints) {
    34.                                 //heal player
    35.                                 FPSPlayerComponent.HealPlayer (healthToAdd);
    36.                
    37.                                 if (pickupSound) {
    38.                                         AudioSource.PlayClipAtPoint (pickupSound, myTransform.position, 0.75f);
    39.                                 }
    40.                                
    41.                                 if (removeOnUse) {
    42.                                         //remove this pickup
    43.                                         Object.Destroy (gameObject);
    44.                                 }
    45.                
    46.                         } else {
    47.                                 //player is already at max health, just play beep sound effect
    48.                                 if (fullSound) {
    49.                                         AudioSource.PlayClipAtPoint (fullSound, myTransform.position, 0.75f);
    50.                                 }      
    51.                         }
    52.                 } else {
    53.                     if (pickupSound) {
    54.                         AudioSource.PlayClipAtPoint (pickupSound, myTransform.position, 0.75f);
    55.                     }
    56.                     InvManager.AddItem (myTransform);
    57.                 }
    58.  
    59.     }
    60. }
    You can also see below how RFPS handles the healing of a player. You will need to know these later when we have to edit the Use item from the inventory ;) The food and drink work in exactly the same manner.

    Code (CSharp):
    1. //heal player
    2. FPSPlayerComponent.HealPlayer (healthToAdd);
    3.                
     
  41. RealSoftGames

    RealSoftGames

    Joined:
    Jun 8, 2014
    Posts:
    220
    technically this should make crafting work as well
     
  42. yummybrainz

    yummybrainz

    Joined:
    Jan 14, 2014
    Posts:
    65
    For food items it is similar to the health kit pickup. Open up the FoodPickup.cs script and edit that file.

    I started by adding another audio clip so instead of hearing an eating noise when picking up food you can add another sound.

    Code (CSharp):
    1. public AudioClip pickupSoundNoEat;//sound to play when picking up food
    Add an autoEat boolean to check if we want to consume the food or place in the inventory. The rest here is the same where we create a reference to the Inventory Manager.

    Code (CSharp):
    1. //Other scripts:
    2.     public bool autoEat = false;
    3.     [HideInInspector]
    4.     public InventoryManager InvManager;
    5.     void Start () {
    6.         InvManager = FindObjectOfType(typeof(InventoryManager)) as InventoryManager; //Get the Inventory Manager object/script.
    7.  
    8.         myTransform = transform;//manually set transform for efficiency
    9.         playerObj = Camera.main.transform.GetComponent<CameraKick>().playerObj;
    10.         FPSPlayerComponent = playerObj.GetComponent<FPSPlayer>();
    11.     }
    Then in the pickupItem function we modify this so it is like below.

    Code (CSharp):
    1. public void PickUpItem(){
    2.         if (autoEat) {
    3.                         //if player is hungry, apply hungerToRemove to hungerPoints
    4.                         if (FPSPlayerComponent.hungerPoints > 0.0f && FPSPlayerComponent.usePlayerHunger) {
    5.                
    6.                                 if (FPSPlayerComponent.hungerPoints - hungerToRemove > 0.0) {
    7.                                         FPSPlayerComponent.UpdateHunger (-hungerToRemove);
    8.                                 } else {
    9.                                         FPSPlayerComponent.UpdateHunger (-FPSPlayerComponent.hungerPoints);  
    10.                                 }
    11.                
    12.                                 //restore player health by healthToRestore amount
    13.                                 if (FPSPlayerComponent.hitPoints + healthToRestore < FPSPlayerComponent.maximumHitPoints) {
    14.                                         FPSPlayerComponent.HealPlayer (healthToRestore);  
    15.                                 } else {
    16.                                         FPSPlayerComponent.HealPlayer (FPSPlayerComponent.maximumHitPoints - FPSPlayerComponent.hitPoints);
    17.                                 }
    18.                
    19.                                 //play pickup sound
    20.                                 if (pickupSound) {
    21.                                         AudioSource.PlayClipAtPoint (pickupSound, myTransform.position, 0.75f);
    22.                                 }
    23.                
    24.                                 if (removeOnUse) {
    25.                                         //remove this food pickup
    26.                                         Object.Destroy (gameObject);
    27.                                 }
    28.                         } else {
    29.                                 //if player is not hungry, just play beep sound
    30.                                 if (fullSound) {
    31.                                         AudioSource.PlayClipAtPoint (fullSound, myTransform.position, 0.75f);
    32.                                 }  
    33.                         }
    34.                 } else {
    35.             if (pickupSoundNoEat) {
    36.                 AudioSource.PlayClipAtPoint (pickupSoundNoEat, myTransform.position, 0.75f);
    37.                     }
    38.                     InvManager.AddItem (myTransform);
    39.                 }
    40.     }
     
  43. yummybrainz

    yummybrainz

    Joined:
    Jan 14, 2014
    Posts:
    65
    Yup for crafting all you are doing is checking if this = this instatiate this object ;)

    I have not had a chance to check out the crafting yet but will for sure.

    I had played around earlier with the idea of collecting resources etc. The method would be the same as the pickups. So for example if you hit on a tree you could use in a pre-defined script.

    Where that script is connected to a wood object.
    Code (CSharp):
    1. InvManager.AddItem (myTransform);
    Then the crafting would check if you have enough wood to build a camp fire. If so then add camp fire to your inventory.
     
  44. RealSoftGames

    RealSoftGames

    Joined:
    Jun 8, 2014
    Posts:
    220
    if so i have seen 1 possible way of this happeneing, give a tree object a health script, and when health <=0 give the death indicator to Spawn wood pickup. but the only problem i have with this is when you shoot the tree it will also cause it to do this, wonder how to make it only work for a specific item, E.g Axe only.
     
  45. yummybrainz

    yummybrainz

    Joined:
    Jan 14, 2014
    Posts:
    65
    Yes you need to check which weapon the character is wielding. That would be the same way that RUST for example handles which weapon/tool is in your hand to determine if you can collect with it.

    I'm working on a sample for this now ;)
     
  46. yummybrainz

    yummybrainz

    Joined:
    Jan 14, 2014
    Posts:
    65
    @SoumiDelRio Can you help explain something in the InventoryManager please? I'm trying to addItems but not destroy them until I tell it. So for example you have a block of wood you want to harvest and I'm sending it via addItem. Every time I do this though the item is destroyed but never calls the Destroy() function. Can you please tell me where this is happening before I lose more hair :)
     
  47. yummybrainz

    yummybrainz

    Joined:
    Jan 14, 2014
    Posts:
    65
    @SoumiDelRio Might be a good Idea to add an isDestroyable bool to the items. That way users can select how they want the item to be removed.

    It will be useful for cases such as above where you want to harvest an object.
     
  48. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,423
    Actually, items that get picked up do NOT get destroyed. Their game objects are deactivated and they are moved as child objects of the inventory manager. In the inventory manager script, you can choose whether to destroy items or spawn them in the game world.
     
  49. yummybrainz

    yummybrainz

    Joined:
    Jan 14, 2014
    Posts:
    65
    Yes I realized that after posting and found the code that does this.

    The problem is when it gets attached to the Inventory Manager it disappears in the stage view.

    What I did was add an isDestroyable bool to the Item then check if its true or not.

    Code (CSharp):
    1.  
    2. if(NewItemScript.isDestroyable){
    3.                    //Changing the settings of the item and parenting it to the inventory object.
    4.                    if(Item.transform.collider !=null)
    5.                     {
    6.                        Item.transform.collider.isTrigger = true;
    7.                    }
    8.                     // Adding the below code to remove errors for container objects.
    9.                     if(Item.transform.renderer !=null)
    10.                     {
    11.                         Item.transform.renderer.enabled = false;
    12.                     }
    13.  
    14.                    
    15.                         Item.transform.parent = MyTransform;
    16.                         Item.transform.localPosition  = Vector3.zero;
    17.                         Item.gameObject.SetActive(false);
    18.                     }
    19.  
    Then attach it once the isDestroyable is set to true.

    Code (CSharp):
    1. if(NewItemScript.isDestroyable){
    2.                     //Changing the settings of the item and parenting it to the inventory object.
    3.                     if(Item.transform.collider !=null)
    4.                     {
    5.                         Item.transform.collider.isTrigger = true;
    6.                     }
    7.                     // Adding the below code to remove errors for container objects.
    8.                     if(Item.transform.renderer !=null)
    9.                     {
    10.                         Item.transform.renderer.enabled = false;
    11.                     }
    12.                  
    13.                  
    14.                     Item.transform.parent = MyTransform;
    15.                     Item.transform.localPosition  = Vector3.zero;
    16.                     Item.gameObject.SetActive(false);
    17.                 }
    18.  
    19.                 Destroy(Item.gameObject); //Destroying the item.
    There are a few problems though. The Amount keeps multiplying now until it hits the max amount. There is also an error when I do set it to destroy the object on stage but I will look into that a little deeper later.
     
  50. RealSoftGames

    RealSoftGames

    Joined:
    Jun 8, 2014
    Posts:
    220
    ok so far a few errors but they fix each other when you follow along, but until you get to the end i get this one

    Assets/!RFPSP/Scripts/Items/FoodPickup.cs(49,100): error CS0103: The name `healthToRestore' does not exist in the current context

    followed exactly till the end and this last food script threw this at me, any ideas on what it could be from
     
    Last edited: Sep 29, 2014
Thread Status:
Not open for further replies.
unityunity