- Home /
A text apears on the screen when you enter a trigger
Hey guys, I need a script that do the following , thank youuu <3 A text apears on the screen when you enter a trigger and goes away when you exit the trigger , and its not a GUItext , thanks
Answer by CPC_Antimark · Sep 21, 2021 at 12:49 PM
So for the text to appear, I used UIText, so I'll give you an example of this to start with. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class TextTrigger : MonoBehaviour {
public Text keycardText;
private bool closeEnough = false;
// Start is called before the first frame update
void Start()
{
closeEnough = false;
keycardText.text = " ";
}
// Update is called once per frame
void OnTriggerEnter(Collider col)
{
if (col.tag == "Player")
{
closeEnough = true;
keycardText.text = "Keycard";
}
}
} This basically makes the text appear when it enters the collider. However, I unfortunately am still trying to figure out the disappearing aspect. If I figure it out, I'll let you know ;)
Your answer
Follow this Question
Related Questions
Making my Text fade in on a trigger 2 Answers
Display a Text/GUI on screen when triggerd with Fadein/Fadeout 1 Answer
fetching a value 1 Answer
On trigger enter fade in gameobject ? 1 Answer
Enter Trigger activate Gui Texture 1 Answer