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);

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.

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