items appearing when a box destroyed by pressing 'e' key

hi everyone, anyone can help me with this coding in c# as i want to press the 'e' key to destroy the box and spawn the objects inside the box..thx..

C# ok that's cool :) But What box? What Objects inside it? All I can say is call the Destroy() method to wreck stuff. And for input management with an 'e' key.

if (Input.GetKeyDown (KeyCode.e))
{
    Destroy("object reference", timer);
}

The destroy method can be read into here

Remember this rule in Q&A. The quality of the answer can not be greater than the quality of the question. It doesn't ALWAYS apply but it's a damm good rule of thumb!

EDIT 11/30/2010 13:46:

The tricky part may be interacting with the environment in that manner. If it's a 2D or 3D world , the interaction must have some sort of range parameter (assuming the character doesn't have arm that can grab stuff at 50 meters distance or more ). Using a raycast maybe more than one, you could determine if you are standing next to an interactable and get the object you just hit with the return value it supplied using the collider as a handle or reference.

Once that's done you need to change the state of that object from closed to opened IF it is interactable of course.

Now that's done you need to do the whole ammo/health thing. You can just ignore what's in the crate untill someone actually opens them if you want. Loading whatever is inside only when needed.

If that has or has not caused the destruction of the box (the opening event) is up to you. But I figure if you don't take it, it just keeps lying on the ground right? If so then the destroy event should only be called once the box object state becomes "empty" (could just be a single bool)

yes it is c#..is like a cube box like any game that can spawn health and ammunition. the steps that i wanted to implement..

  1. a character go to the box
  2. press 'e' to open the box
  3. the box is destroyed and the health and ammo spawn out

some codes that i implemented:

public GameObject[] items=new GameObject[2]; public bool crateDestroyed = false;

void Update()
{
    if (crateDestroyed)
    {
        Vector3 position = transform.position;

        foreach (GameObject item in items)
        {
            if (item != null)
            {
                Instantiate(item, transform.position, Quaternion.identity);
            }
        }

        Destroy(GameObject);
    }
}