How do I add a char to a string?

Hi, so I’m trying to make a pokemon or whateverRetroGameYouWant style Task bar where you get you next objective. Currently I’m trying to make this happen through having to strings, one is my objective and the other one should get updated with a new character each frame(I know that this is a crappy solution but I will fix this). At the moment I get my next character through a char variable but I don’t know how to add this to my string.

Heres my code:

public Text TaskBoxText;
    public string Task;
   
    //[HideInInspector]
    public bool setTaskActive = true;
    int TaskLength;
    [HideInInspector]
    public string currTaskText;
    public char nextLetter;
   
    void Start()
    {
        TaskLength = Task.Length;
    }

    void Update()
    {
        if(setTaskActive)
        {
            StartCoroutine(WriteTask());
        }
    }
   
    IEnumerator WriteTask()
    {
        for(int i = 0; i < TaskLength; i++)
        {
            char nextLetter = Task[i];
           
           
            yield return null;
        }
    }

if you want to place char in the end of the string it’s as simple as

string += char;

If you want to place char or string in for example middle of the string you may use string.Insert

string currTaskText = "hello";
int position = 2;

currTaskText = currTaskText.Insert(position, "text");

position is as it says position where your code should put a “text” in currTaskText

Output should be: hetextllo

4 Likes

Dude you don’t know how dumb I fell right now :slight_smile: Thanks for the reply I tryied it and it worked perfectly thanks man