- Home /
How would i display text and get rid of it
I am trying to get a text displayed and then have it removed to use for later. i have a Raycast set up and it detects when it hits an intractable object then displays "Press E to interact but i cant get that to go away i want it to disappear and reappear when i come in contact with another intractable object. this is what i have so far. if (whatIHit.collider.gameObject.GetComponent() != null) // if the object is interactable { interact.enabled = true; interact.text = "Press 'E' to interact"; partFX = whatIHit.collider.gameObject.GetComponent();
}
else if (whatIHit.collider.gameObject.GetComponent<Interactions>() != null)
{
interact.enabled = false;
interact.text = "";
}
the full code is not showing this is it
if (whatIHit.collider.gameObject.GetComponent() != null) // if the object is interactable { interact.enabled = true; interact.text = "Press 'E' to interact"; partFX = whatIHit.collider.gameObject.GetComponent();
}
else if (whatIHit.collider.gameObject.GetComponent<Interactions>() != null)
{
interact.enabled = false;
interact.text = "";
}
We need a little more of the code.. I would paste the whole thing in as this isn't telling us what function you are in. What gameobjects you have. To me this seems that you want to enable interact when you click an object or your mouse enters it's area then disable interact when it leaves the object?
When do you want the message to be disabled only when you click another object? After a certain amount of time? After mouse leaves object? Other?
Your answer
![](https://koobas.hobune.stream/wayback/20220612105609im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUI Text not displaying in my game space 2 Answers
How to get new text from this? 1 Answer
Need Text to Display After 5 Seconds 1 Answer
Interacting with many objects and general questions (2D) 0 Answers
I have a C# script with InputField and I want to get text from this input field to another script 0 Answers