OnTriggerEnter only fires in the first frame the collision happens, GetKeyDown only fires in the first frame the key is pressed. You would need to hit the button in the exact frame the collision first occurs for it to work…
Here is the working code below for anyone in the future who wants to implement a pick-up system in their game (perhaps not the most efficient solution :P)
using UnityEngine;
public class ObjectPickup : MonoBehaviour
{
public float bookweight = 1.2f;
GameObject book;
void Awake ()
{
}
void Start () {
book = GameObject.FindGameObjectWithTag ("book");
}
void OnTriggerStay (Collider other)
{
// If the entering collider is the book...
if(other.gameObject == book && Input.GetKey("e"))
{
ScoreManager.currentweight += bookweight;
Destroy(other.gameObject);
}
}
}