How to pick up a key item in a scene?

Hello,
I am currently working on a FPS game that requires a use key. What I mean by a use key, is that when the player comes up to a item, they can hit a key, and It will add the item to there inventory. I already have my inventory set up, but this is really stumping me D:
If anyone has a way to do this with code, colliders or whatever, please answer this!
Thank you in advance!

  • Nikolai

Here is an idea of a simple algorithm to get your task done.

  1. Setting the key object with a collider as trigger.
  2. Check if a game object tagged as “MyPlayer” enter into collision with the key,
  3. If so, add it into your inventory by using SendMessage.
  4. delete key object from scene

After setting your key object as a trigger, you can do something like:

function OnTriggerEnter (other : Collider) {
    if (other.tag == "MyPlayer") {
       other.SendMessage("YourFunctionToAddKeyIntoInventory", "NumberToAdd");
       Destroy(this.gameObject);
    }
}