Pick up an item with colliders, using C#

I’ve been looking around trying to find a tutorial that utilizes C# for a script that allows me to pick up items with collision. Possibly a button press such as “e” or similar.

I know how to set up the colliders on the objects and such, I just don’t know where to begin with the scripting part where I can walk over the item and have it disappear and enable an item I already have disabled in the background for use.

For anyone in 2020 trying to implement this into their game this works.
I didn’t have to add any reference to the player controller only the input button.
This was attached to my object for pickup.

void OnTriggerStay(Collider other) // If ammo object collides with any collider…
{

    if ((other.gameObject.tag == "Player") && (Input.GetButton("Pickup")
  1. Pickup colliders must be Trigger so you can walk over.

  2. Write a script on the character to handle the OnTriggerEnter event.

  3. In this event, store the pickup trigger object into a variable (Which is reachable from keyboard control script)

  4. In keyboard control script (maybe a global function or maybe in character script) try to detect if “E” key is down

  5. if E is down, you have the object you want to interact in the variable set from the step 3.

@klown use this script-

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

    public float speed;

    private Rigidbody rb;

    void Start ()
    {
        rb = GetComponent<Rigidbody>();
    }

    void FixedUpdate ()
    {
        float moveHorizontal = Input.GetAxis ("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");

        Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

        rb.AddForce (movement * speed);
    }

    void OnTriggerEnter(Collider other) 
    {
        if (other.gameObject.CompareTag ("Pick Up"))
        {
            other.gameObject.SetActive (false);
        }
    }
}