Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 RealGamesStudio · Feb 26, 2017 at 01:22 PM · instantiateobjectreplaceattachmentequipment

REPLACING INSTANTIATED OBJECT

Hello, everyone! I've been trying to find a solution for my problem for a while and I can't manage to do so. I am trying to create a mechanic in which the equipment of the player changes via a function. Everything is working - the item goes from the inventory to the equip tab, it changes player stats and the items can be replaced, but that's not the case with the objects (weapons) I am trying to spawn. The first use is fine because it spawns perfectly, but I cannot find a way for the upcoming change of equipment just to replace the old one. And right now they can be 300 weapons at the same time and that's not cool. Here is the part of the code where this happens -

 public GameObject handler;
 
 
     public void Use_Item(int _itemID){
         Item_Data.Item item = Item_Data.instance.Get_Item(_itemID);
 
         if(item != null){
             if(item.equipment_Type == Item_Data.Equipment_Type.Null && item.gold == false){
                 if(item.potion == true){
                     
                     AddEffectItemToPlayer(item);
                     
                     bag_item[indexInventory].item_amount -= 1;
                     if(bag_item[indexInventory].item_amount <= 0){
                         bag_item[indexInventory].item_id = 0;
                         bag_item[indexInventory].item_amount = 0;
                         bag_item[indexInventory].equipmentType = Item_Data.Equipment_Type.Null;
                     }
                 }
             }else if(item.equipment_Type != Item_Data.Equipment_Type.Null){
                 Debug.Log("Equipment");
                
                 if (item.Gear != null)
                 {
                     handler = Instantiate(item.Gear,  transform.position , transform.rotation );
                     handler.transform.parent = transform;
                    
                 }
                 
 
                 for (int i = 0; i < equipment[0].slotEquipmentRect.Length; i++){
                     if(item.equipment_Type == equipment[0].slotEquipmentRect[i].equipType){
                         
                         if(playerController.classType == item.require_Class || item.require_Class == ClassType.None)
                         {
                             if(slotEquipment_item[i].item_id == 0){
                             AddStatEquipmentToPlayer(item);
                             slotEquipment_item[i].item_id = item.item_ID;
                             slotEquipment_item[i].equipmentType = item.equipment_Type;
                             bag_item[indexInventory].item_id = 0;
                             bag_item[indexInventory].item_amount = 0;
                             bag_item[indexInventory].equipmentType = Item_Data.Equipment_Type.Null;
                             bag_item[indexInventory].linkIndex = -1;
                         }else{
 
                             item.Gear.gameObject.SetActive(false);
                                 
                             Item_Obj _item_obj = new Item_Obj();
                             handler = Instantiate(item.Gear, transform.position, transform.rotation);
                             handler.transform.parent = transform;
                               _item_obj.item_id = slotEquipment_item[i].item_id;
                             _item_obj.euipmentType = slotEquipment_item[i].equipmentType;
                             _item_obj.item_amount = 1;
                             
                             RemoveStatEquipmentToPlayer(Item_Data.instance.Get_Item(slotEquipment_item[i].item_id));
                             
                             slotEquipment_item[i].item_id = item.item_ID;
                             slotEquipment_item[i].equipmentType = item.equipment_Type;
                             
                             AddStatEquipmentToPlayer(item);
                             
                             
                             bag_item[indexInventory].item_id = 0;
                             bag_item[indexInventory].item_amount = 0;
                             bag_item[indexInventory].equipmentType = Item_Data.Equipment_Type.Null;
                             bag_item[indexInventory].linkIndex = -1;
                             
                             Pickup_Item(_item_obj);
                             }
                         }    
                     }
                 }
             }
         }


I will be REALLY thankful if you help me with this guys! Thank you!

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I replace an object while keeping the references to that object? 2 Answers

Instantiate and destroy on given location 1 Answer

Referencing a variable in another script possibly not working? 0 Answers

How to detect if object is within another object? 0 Answers

Reference by Instance ID? 2 Answers


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