How to get similar scripts working on different objects?

I am trying to create a graveyard. In this graveyard you can go up to a stone, hit “E” and it will bring up a short statement in a GUI box and then you can hit exit and move onto the next one.

Anytime I try to copy the file down below and place it on a new stone so I can change the text inside to match a different tombstone, it does not work. The “Press “E” to interact” does not come up, pressing “e” does nothing. It works on the original but creating a new file does not do anything.

I’ve also tried doing it by object tag which also doesn’t work. It only worked on one object and no others.

Let me state the question again as clear as possible: How can I make it so the same thing happens on every stone (show the GUI text and an exit button) while also being able to have different GUI text in the GUI Box that is created?

using UnityEngine;
using System.Collections;

public class InteractA : MonoBehaviour {
	public GUIText target;
	private bool selected = false;
	private GameObject ply;
	private GameObject cam;
	private bool menu = false;
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		selected = false;
		target.text = "";
	}
	
	public void OnLookEnter(){
		target.text = "Press E to interact";
		selected = true;
	}

	void OnGUI() {
		ply = GameObject.Find ("First Person Controller");
		cam = GameObject.Find ("Main Camera");
		Event a = Event.current;
		if(a.isKey && a.character == 'e' && selected){
			target.enabled = false;
			ply.GetComponent<MouseLook>().enabled = false;
			ply.GetComponent<CharacterMotor>().enabled = false;
			ply.GetComponent<FPSInputController>().enabled = false;
			cam.GetComponent<MouseLook>().enabled = false;
			Screen.showCursor = true;
			menu = true;
		}
	if(menu){
			GUI.Box (new Rect(0, Screen.height/2+125, Screen.width, Screen.height/2), "Together

Harold John
Washburn
Feb. 27, 1940
Jan. 2, 2005");

			if(GUI.Button(new Rect(95, Screen.height/2+235, 800, 30), "Exit"))
			{
			target.enabled = true;
			ply.GetComponent<MouseLook>().enabled = true;
			ply.GetComponent<CharacterMotor>().enabled = true;
			ply.GetComponent<FPSInputController>().enabled = true;
			cam.GetComponent<MouseLook>().enabled = true;
			Screen.showCursor = false;
			menu = false;
			target.enabled = true;
}
	}
}
			}

You need to call OnLookEnter on each instance of the script when your player is close enough to the stone. You need to call this method every frame after the Update, a good contender is LateUpdate. Calling the method sets your selected true, which in turn causes pressing ‘e’ to function.

That seems rather complicated to me, I would just rename OnLookEnter to OnTriggerEnter, then put that code in Update into OnTriggerExit

I would also use Input.GetKey(KeyCode.E) instead of that event hassle you currently have in OnGUI. But you know: “If it ain’t broken, don’t fix it.”