How to make an object appear after collecting items?

what I want to do is have the player collect three items, then a key will appear. I think it has something to do with instantiate but I’m not sure. here’s my code so far

var jewels : int=0;

function OnTriggerEnter( other :
Collider ) {
if (other.tag == “gem”) {
jewels += 1;
Destroy(other.gameObject);
}
}

what would be a really simple way of having this fourth object appear?

You’re right. “Instantiate” is the right way to make an object appear.

var jewels : int=0;
var key:GameObject;

function OnTriggerEnter( other : Collider ) { 
  if (other.tag == "gem") { 
    if(++jewels >= 3){ 
       Destroy(other.gameObject); 
       Instantiate(key,Vector3(200,200,200),Quaternion.identity);
       }
}

This is attached to the player. The collision you got it already. Then it increases and checks if you have three gems. It is not necessary but recommended to <= or >= because if for some uncontrolled reasons (you are never free from bugs) your gem counter goes beyond 3 you will never get your key. Though pretty unlikely but who knows…
The other object is destroyed and a new one is instantiate.

Instantiate (object,position,rotation);

Drag and drop the key prefab in to the key slot in the Inspector. Instantiate will create that object at the position given in parameter 2. In my case, at 200,200,200. Quaternion.identity is a “fancy” name for no rotation. Without too much details, a Quaternion is a rotation system in 4D.

function OnTriggerEnter( other : Collider )
{
if (other.tag == “gem”) {
jewels += 1;
Destroy(other.gameObject);
Instantiate (Key, Vector3(1,1,1), Quaternion.identity);
}
}

All you need is a frepab named Key