Search Unity

Decoding Text Effect

Discussion in 'Scripting' started by Micio_del_Cheshire, Sep 25, 2018.

  1. Micio_del_Cheshire

    Micio_del_Cheshire

    Joined:
    Oct 24, 2013
    Posts:
    28
    Hello there! I have a TextMesh pro text serving as console in the game.
    I want to display on it a Decoding effect (e.g. trash hacker movies)

    Code (CSharp):
    1.  private static System.Random random = new System.Random();
    2.  
    3.     private string ShuffleString(string s, int i)
    4.     {
    5.        
    6.         final = "";
    7.  
    8.         //final starts with first i char of string s
    9.         for (int j = 0; j < i; ++j)
    10.         {
    11.             final += s[j];
    12.         }
    13.         //append random chunk at the end
    14.         string randChunk = RandomString(s.Length - i);
    15.         final += randChunk;
    16.  
    17.         return final;
    18.     }
    19.  
    20.     //generate random string of chars of length.
    21.     public static string RandomString(int length)
    22.     {
    23.         const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    24.         return new string(Enumerable.Repeat(chars, length)
    25.           .Select(s => s[random.Next(s.Length)]).ToArray());
    26.     }
    I tried with those scripts, but then I couldn't make them work because:
    • I can't understand how can I re-write con the same output in a TextMeshPro.text area with other lines already written (and they have to stay safe)
    • the coroutine system I put them in can't return the "work in progress" string

    In the end, I want to write over and over on a certain line in text field (with other lines that have to keep unchanged) a string compsed of random chars (that continue changing randomly), and every now and than a character of the final string s appears and stay, until all the string is revealed.

    Can anyone please help me?
    Thanks a lot
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    When you start your effect, copy the current value of the text field. Find the last newline character and split the string there. Only run the effect on the string after the newline.