• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by theredkey · Dec 09, 2016 at 03:06 PM · uitextresethide

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)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ralp7 · Dec 09, 2016 at 03:45 PM 0
Share

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);
     }
 }
 

2 Replies

· Add your reply
  • Sort: 
avatar image
2

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 = "";
      }
  }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by theredkey · Dec 10, 2016 at 08:36 AM

@Ralp7

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

110 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Hide (not delete) text after given time..? 1 Answer

MissingReferenceException: The object of type 'Text' has been destroyed but you are still trying to access it. 5 Answers

how do i change max size value of text component unity? 1 Answer

Making a growing number 1 Answer

BCE0022: Cannot convert 'String' to 'int' 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges