How this Script is Working????

Here i attach the script used to get char in string one by one ,bt i dnt know how its s working???

kindly help

using UnityEngine;
using System;
using System.Collections;

public class AnimText : MonoBehaviour
{

public int currentPosition=0;
public float Delay= 0.1f; // 10 characters per sec.
//public string Text=“hihellohwru”;

public string Text=“”;
public int textlength;

public string[ ] additionalLines;

//char[ ] b = new Char[Text.Length];

void WriteText(string aText)
{
//guiText.text = “”;
this.gameObject.GetComponent ().text = " ";
currentPosition = 0;
Text = aText;
}

// Use this for initialization
void Start()
{
//TextOk();
StartCoroutine(“TestTwo”);

}

IEnumerator TestTwo()
{
print (“hi” + additionalLines);
foreach (string S in additionalLines)

Text +=“\n”+S;
while (true) {

if (currentPosition < Text.Length)

this.gameObject.GetComponent ().text += Text [currentPosition++];
yield return new WaitForSeconds (Delay);

}
}

}

1 Like

Debug it and follow the code flow line by line.

If you can’t understand what is happening in specific line just refer to documentation on Unity or C#.

Try that and if you’re stuck you can come back with a specific question this time.

k ,just to know when WriteText() is called?

hi,thanks for ur reply.i want to know hw the text is inserted to add[ ] string array?

You should clean up your code if anyone is to read it: Using code tags properly - Unity Engine - Unity Discussions
Did you actually do the debug? I mean if you do you can see how that happens step by step literally in front of your eyes.
Any particular moment you get confused about?

ya i do it,just to know how foreachloop(String s in String)?

Google is your friend, you know that right?

thanksssss man!!!