Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
avatar image
-1
Question by AlexTuh · Jun 04, 2020 at 03:39 PM · shadershaderseffecteffectsmonitors

Smooth text disappear after erased like in old monitors.

Hello, I wanted to create an effect like in this video.

I'm talking about text smooth disappearing after it was erased. So I want to create the same effect for TMPro or some other text that when I erase one letter it will remain on the background and smoothly disappear.

Is this possible?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by exploringunity · Jun 04, 2020 at 06:46 PM

Hey @AlexTuh,

Yes, this is possible. My idea is to have two text fields on top of each other -- one is the one you are currently writing to, the other is the one that is fading/invisible, and you swap them out on each new line of dialogue. Below is a simple, but complete example demonstrating the concept -- press spacebar a few times to test it. First a couple screenshots showing the setup:


overview


And the settings for TMP Text 2 (TMP Text 1 is the same, but without any initial text):

tmp settings


Finally, the code:

Assets/DialogueManager.cs

 using TMPro;
 using UnityEngine;
 
 public class DialogueManager : MonoBehaviour
 {
     public TMP_Text txt;
     public TMP_Text txt2;
 
     TMP_Text activeTxt;
     TMP_Text fadingTxt;
 
     public float secondsPerChar = 0.03f;
     public float secondsToFade = 1.0f;
 
     int messageIdx; // Which message is displayed
     int charIdx; // Which character of the message is being typed
     float timeSinceLastChar;
 
     float fadingTxtAlpha; // 0 = invisible, 1 = visible
 
     bool waiting = true; // Are we waiting for the user to advance the dialogue?
 
     void Start()
     {
         activeTxt = txt;
         fadingTxt = txt2;
     }
 
     void Update()
     {
         if (waiting) { WaitForUserInput(); }
         else { DisplayMessage(); }
         FadeBackgroundMessage();
     }
 
     void WaitForUserInput()
     {
         if (messageIdx == messages.Length - 1) { return; } // No more messages
 
         if (Input.GetKeyDown(KeyCode.Space))
         {
             AdvanceDialogue();
             waiting = false;
         }
     }
 
     void AdvanceDialogue()
     {
         // Reset the message/char indices for the new message
         messageIdx++;
         charIdx = 0;
 
         // Clear out the last faded text and reset its alpha
         fadingTxtAlpha = 1f;
         fadingTxt.text = string.Empty;
         fadingTxt.alpha = fadingTxtAlpha;
 
         // Swap out the active and fading text boxes
         var tmpTxt = activeTxt;
         activeTxt = fadingTxt;
         fadingTxt = tmpTxt;
     }
 
     void DisplayMessage()
     {
         var message = messages[messageIdx];
 
         // Allow user to skip typing animation
         if (Input.GetKeyDown(KeyCode.Space))
         {
             activeTxt.text = message;
             charIdx = message.Length;
         }
 
         // Are we done typing this message?
         if (charIdx >= message.Length)
         {
             waiting = true;
             timeSinceLastChar = 0f;
             return;
         }
 
         // Type the next character if we've waited long enough
         while (timeSinceLastChar >= secondsPerChar)
         {
             activeTxt.text = message.Substring(0, charIdx + 1);
             charIdx++;
             timeSinceLastChar -= secondsPerChar;
         }
         timeSinceLastChar += Time.deltaTime;
     }
 
     void FadeBackgroundMessage()
     {
         if (fadingTxtAlpha > 0f)
         {
             fadingTxtAlpha -= Mathf.Clamp01((1 / secondsToFade) * Time.deltaTime);
             fadingTxt.alpha = fadingTxtAlpha;
         }
     }
 
 
     string[] messages = new[] // Some test messages to display
     {
         "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
         "Suspendisse venenatis quam id ante viverra, et suscipit purus posuere.",
         "Nam non iaculis purus, a varius arcu.",
         "Integer fermentum molestie turpis, sit amet pulvinar est viverra in.",
         "Morbi pretium enim eu pellentesque aliquet.",
     };
 }



screenshot-11.png (68.0 kB)
screenshot-12.png (66.8 kB)
Comment
Add comment · Show 3 · 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 AlexTuh · Jun 08, 2020 at 10:50 AM -1
Share

It's not what I wanted, I meant if I erase one letter from the big text for example I have text like this: "lorem ipsum" and I erase one letter and I have this: "lorem ipsu" so letter "m" need to fade out like in that video.

avatar image exploringunity AlexTuh · Jun 08, 2020 at 05:03 PM 0
Share

Sorry, I misunderstood what you were looking for. It sounds like you should be able to achieve the effect you're describing by changing the alpha property of multiple strings with some timer(s) -- similar to the code sample I provided, but fading characters one-by-one ins$$anonymous$$d of typing them one by one. What sort of things have you tried so far?

avatar image AlexTuh exploringunity · Jun 09, 2020 at 04:06 PM 0
Share

I tried applying render texture to a material and making layers behind the text so then I will have a slight delay between text and background, I used C# scripts and It was pretty bad because it was super inefficient.

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.

Follow this Question

Answers Answers and Comments

205 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 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

Shader Material in Game view 0 Answers

Visual Effect Graph strange problem 0 Answers

Freezing effect on camera 0 Answers

Post-Effects & Shaders issue 0 Answers

Material is not visible in android build but works fine in editor? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges