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 DaUr3 · Jul 29, 2018 at 05:09 AM · instantiate prefabactiveitemsshop

Spawning Items from In Game Shop and Adding Items to Inventory

I successfully set up my shop, and it works by adding GameObjects (Items) to the Player's Inventory. Unfortunately, I have run into another issue. I am using an ItemManager to spawn prefab clones and then I add those clones to the Player's Inventory and set the world items as not active.

Is there a way to do this without using Instantiate? Or do I have to spawn an item then add it to the layer inventory? Also is setting using SetActive better than using Destroy and Instantiate every time you get rid of and add an item onto the scene?

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

1 Reply

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

Answer by Carterryan1990 · Jul 29, 2018 at 07:28 AM

You could instead create a child gameobject on your player and call it a container. Once your player picks up an object/item you would set that object/items parent to the container object along with it’s position. And if you don’t want the object visible just SetAactive(false).I think this is what your asking? If not please elaborate more and I’ll be glad to help.

Comment
Add comment · Show 4 · 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 Carterryan1990 · Jul 29, 2018 at 07:35 AM 0
Share
 Public Transform Container;
 bool item_should_be_deactived;
 
 void OnTriggerEnter(Collider other)
 { 
   If(other.tag == “itemTag”)
 { 
  PickUpItem(other.gameObject);
 }
 }
 
 void PickupItem(Gameobject item){
 { 
 Item.transform.setParent(container);
 Item.transform.position = container.position;
 If(item_should_be_deactived)
 {
 Item.setactive(false):
 }
 }
avatar image DaUr3 · Jul 29, 2018 at 07:41 AM 0
Share

Yeah thats what I was talking about. Thanks for the help!

avatar image Carterryan1990 DaUr3 · Jul 29, 2018 at 07:43 AM 0
Share

Awesome glad I could help! If you can mark this as answered it would be greatly appreciated!

avatar image DaUr3 Carterryan1990 · Jul 30, 2018 at 02:39 AM 0
Share

Got you brother.

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

88 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 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 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 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 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

activating and deactivating gameObject on keypress? 1 Answer

My shop system script is not working 2 Answers

PlayFab: KeyNotFoundException: The given key was not present in the dictionary. 0 Answers

May I know how to reactivate an object that deactivated? 1 Answer

Prefab to save active status of sub Object 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