Search Unity

How this Script is Working????

Discussion in 'Scripting' started by hariavm, Aug 20, 2014.

  1. hariavm

    hariavm

    Joined:
    Aug 18, 2014
    Posts:
    73
    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<TextMesh> ().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<TextMesh> ().text += Text [currentPosition++];
    yield return new WaitForSeconds (Delay);


    }
    }

    }
     
  2. toreau

    toreau

    Joined:
    Feb 8, 2014
    Posts:
    204
  3. Pirs01

    Pirs01

    Joined:
    Sep 30, 2012
    Posts:
    389
    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.
     
  4. hariavm

    hariavm

    Joined:
    Aug 18, 2014
    Posts:
    73
    k ,just to know when WriteText() is called?
     
  5. hariavm

    hariavm

    Joined:
    Aug 18, 2014
    Posts:
    73
    hi,thanks for ur reply.i want to know hw the text is inserted to add[] string array?
     
  6. Pirs01

    Pirs01

    Joined:
    Sep 30, 2012
    Posts:
    389
  7. hariavm

    hariavm

    Joined:
    Aug 18, 2014
    Posts:
    73
    ya i do it,just to know how foreachloop(String s in String)?
     
  8. Pirs01

    Pirs01

    Joined:
    Sep 30, 2012
    Posts:
    389
  9. hariavm

    hariavm

    Joined:
    Aug 18, 2014
    Posts:
    73
    thanksssss man!!!!!!