• 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
Question by Nieuwoudt · Nov 25, 2017 at 09:13 AM · itemsitem pickup

Picking up and object and then dropping it again

I am trying to drop the axe at the player's feet.

public class playerController : MonoBehaviour {

 public GameObject playerObject;
 public GameObject Stone_Axe_db;
 public GameObject Stone_Axe;
 public bool hasStoneAxe = false;
 public bool axeEquipped = false;


 void Update()
 {
     if (Input.GetKeyDown(KeyCode.G))
     {
         if (axeEquipped)
         {
             //Create a new Stone_Axe object at the playerObject's position
             Stone_Axe_db.SetActive(false);
             hasStoneAxe = false;
             axeEquipped = false;
         }
     }
 }

 private void OnTriggerEnter(Collider collision)
 {
     if (collision.gameObject.name == "Stone_Axe" )
     {
         Stone_Axe_db.SetActive(true);
         hasStoneAxe = true;
         axeEquipped = true;
        //Get rid of the object 
     }
 }

}

I tried changing active from false to true, but I think that means its just the same object going invisible and visible again? I want to delete the object when I pick it up, and then create another instance of it when I drop it. I tried using destroy() and then instantiate() but I get errors.

Can someone please help me with what I need to put where the comments are to make this work? I am totally new to c# and Unity. TIA.

Comment

People who like this

0 Show 1
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 shakecaine · Nov 25, 2017 at 10:17 AM 0
Share

Using SetActive allows you to enable end disable object. You can see how it reacts in the editor while in playmode to get full idea. Though disabling an object makes it, so you cannot access its properties while disabled. It is not the same as making it invisible. Object has all of its properties disabled.
Basically you want to disable Axe that is on the ground when you "Pick it up" and make it appear again when you drop it right?
If so following question is: Is an axe an object which properties never change?
If so you could make a prefab out of it by dragging it to the project folder and save it. Then you just destroy an object in the scene and whenever you drop it you just Instantiate new one from the prefab. If not then you can also use a prefab but you will need to store properties of the objects your character picked up.
Some errors from destroying an object can be easily fixed, so don''t worry so much about that as there is plenty of solutions.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

72 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

Related Questions

Using enums to design an inventory system? 1 Answer

Need help with the pickup mechanic! 1 Answer

Best Way to do Regular Items and Weapons/Intractable/Special Items. 1 Answer

Unity 2021 MLAPI documentation help!! 0 Answers

How to Make an Object Pickup System? 0 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