UI Text not displaying for all game objects
Hi All, I have a UI text that displays anytime the player gets within 1.5 distance of a game object the player can interact with. The text says "Press (F)" but it only enables when I get within the stated distance of the first of these objects I put in the game. The second object and a third test object, shows the text is active on the console, but the text is not displaying in game. I can still press F to pick up the object, but the text just isn't displaying. Below are screenshots and my game object code. Also, it doesn't matter which game object I walk over to first. The first of the game objects inserted into the game is still the only object that will display the text prompt to press F. All settings are the same that I can see and I've inserted all the correct objects and texts in the Inspector. Any idea what is wrong or what I am missing?
Here's the script for the game object:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class GameObjectController : MonoBehaviour { public float detectionDistance; public GameObject lostGameObject; //Game object that should enable the UI Text public GameObject foundGameObject; //activates on Player's person when the F key is pressed public GameObject target; public Text dialoguePrompt; //The message that displays telling the player to press F
// Start is called before the first frame update
void Start()
{
foundGameObject.SetActive(false);
}
// Update is called once per frame
void Update()
{
float distance = Vector3.Distance(target.transform.position, transform.position);
if (distance < detectionDistance)
{
//dialoguepanel.SetActive(true);
dialoguePrompt.enabled = true;
Debug.Log(dialoguePrompt);
if (Input.GetKey(KeyCode.F))
{
dialoguePrompt.enabled = false;
Destroy(gameObject);
foundGameObject.SetActive(true);
}
}
if (distance > detectionDistance)
{
dialoguePrompt.enabled = false;
}
}
}