How to hide/reset a Text object (without disabling)
I want to add dialogue to my little game and i ran into a problem. I can get the text to show up and play the way i want but when I leave the triggerzone which sets active/inactive the text in the middle of the dialogue, it seems to freeze. When I reenter the triggerzone only the frozen part of the dialogue shows up and i can no longer interact with the text (go to the next part of it etc.)
It seems this freezing is caused by my deactivation of the text through the trigger zone. disableing the renderer also does not seem to help as neither the text nor the panel use one.
are there ways or commands (preferably c#) that can hide UI elements or reset them (position/size/rotation resetting is what i found but not general resetting in terms of everything)
You can create a button and change its color alpha to 0. Then create a child text object. You can set active or inactive the text by using button object. I wrote this code, when mouse enters the button object, text shows up. When mouse exits the button, the text disappear. Think this button as a Game$$anonymous$$anager. I hope it is want you want.
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class ActiveText : $$anonymous$$onoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
Text myText;
void Start ()
{
myText = GetComponentInChildren<Text>();
}
public void OnPointerEnter(PointerEventData eventData)
{
myText.gameObject.SetActive(true);
}
public void OnPointerExit(PointerEventData eventdata)
{
myText.gameObject.SetActive(false);
}
}
Answer by RobAnthem · Dec 10, 2016 at 09:57 AM
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class ActiveText : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
string myString;
Text myText;
void Start ()
{
myText = GetComponentInChildren<Text>();
}
public void OnPointerEnter(PointerEventData eventData)
{
myText.Text = myString;
}
public void OnPointerExit(PointerEventData eventdata)
{
myText.Text = "";
}
}
Answer by theredkey · Dec 10, 2016 at 08:36 AM
Thank you, but the ".SetActive(false);" command (which is in your code as well) is what causes my text to freeze. I am looking for alternatives for it.
Your answer
Follow this Question
Related Questions
Hide (not delete) text after given time..? 1 Answer
UI Canvas Anchor points are stuck in the bottom left corner and disabled when in overlay mode. 1 Answer
How To Load TTF Font From External File 0 Answers
Adventure Game Help 0 Answers
How to make Textmesh Pro effects on only one text object? 1 Answer