Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by BOT-Alex · Oct 04, 2019 at 11:23 PM · objectdestroyvaluedestroy objectbox

Can you get a value from a object when destroyed?

I want to know if there is any way to get a value assigned to a box but only when the box is destroyed. Using Destroy(other.gameObject);

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 SpaceManDan · Oct 05, 2019 at 05:45 AM 0
Share

Sure you can but I think we all need to know which value you want to get. What do you want to get from the box?

avatar image BOT-Alex SpaceManDan · Oct 05, 2019 at 09:36 AM 0
Share

there will be different values on boxes but it will only give out points that is set to the box

2 Replies

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

Answer by SpaceManDan · Oct 06, 2019 at 01:35 AM

I'm going off concept of execution here since I don't have any real details. Here is an example of one way this can be done.

Create a GameObject and name it BoxOfPoints. Now add a new tag to your project in tags and layers and call that tag "BoxPoints".

Now create a new script and call it "BoxInfo". FIRST, add the script to the new box you just created. The box called BoxOfPoints should now have an empty script on it called BoxInfo. Open the script BoxInfo for editing and put the following code in it.

  public class BoxInfo : MonoBehaviour
 {
     public int boxPoints;

     private void Start()
     {
          transform.tag = "BoxPoints";
          boxPoints = 10;
     }
 }

Now, create a new script and name it PlayerPoints. Add it to the player. You should now have an empty script called PlayerPoints on the players gameObject. Open the script PlayerPoints for editing and add the following code.

 public class PlayerPoints : MonoBehaviour
 {
     public int playersBoxPoints;

     private void OnCollisionEnter(Collision collision)
     {
         if(collision.transform.tag == "BoxPoints")
         {
             BoxInfo boxInfo = collision.transform.GetComponent<BoxInfo>();
             playersBoxPoints += boxInfo.boxPoints;
             Destroy(boxInfo.gameObject);
         }
     }
 }


Now, duplicate the box so you have like 5 or 6 of them all in different locations. Every time the player collides with the box, it will add 10 points to the players points and destroy that instance of the box gameobject. Now keep in mind, you could do this from any object, like an arrow shot from a bow could feed the points to the player... or anything really. But just for a concept, this should get you thinking in the right direction. Now if you want to share your code with us. I can be WAY more specific because you can do something like this literally thousands of ways.

Hope this helps.

Comment
Add comment · Show 1 · 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 BOT-Alex · Oct 10, 2019 at 01:46 PM 0
Share

i don't have time to test it today but at a later date ill check.

thank you.

avatar image
0

Answer by Mokomaki · Oct 05, 2019 at 09:33 AM

Well thats vague... But couldent you just send the value out right before you destroy it?

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 BOT-Alex · Oct 05, 2019 at 09:36 AM 0
Share

there will be different values on boxes but it will only give out points that is set to the box

avatar image Mokomaki BOT-Alex · Oct 05, 2019 at 09:46 AM 0
Share

Ok so do you destroy the box from its own script or another script ?` I would have a script on the box that could hold the number of points it will give and right before you destroy it you could just usee the same reference you use to destroy it in the first place to get the variable that holds the number of points. I would suggest sharing the bit of code where you destroy the box.

Hope you find what you need :)

avatar image BOT-Alex Mokomaki · Oct 05, 2019 at 09:51 AM 0
Share

Yeah absolutely.

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

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

Objects getting destroyed in unity test, but only sometimes in the phone app 0 Answers

Problem after 5 seconds destroy/deactivate component 1 Answer

Simple call animation then destroy? 0 Answers

How do i add blinking effect to an instantiated object ? 0 Answers

Destroying an object in a matrix 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