ReadLine to a Variable

I have a .txt file (filled with a string of numbers each on a separate line). I can read this fine and print it to the console window. I now want to take those numbers and get them into where the question marks are below:

transform.Translate(Vector3(0,0,??)*Time.deltaTime); 

The code I have so far is:

//import System; (I am not sure when I need to import this?)
import System.IO; 

print(Application.dataPath);
var wordFile = "positions2.txt";
print(Application.dataPath+"/"+wordFile);


function Start () {
var sr : StreamReader = new StreamReader(Application.dataPath +"/"+ wordFile);

line = sr.ReadLine();
		while (line != null) {
			print(line);
			line = sr.ReadLine();
		}
		sr.Close();
		
		}

//function Update () {
//transform.Translate(Vector3(0,0,sr)*Time.deltaTime);
//}

Advice on how to get the numbers into a variable that I can then use for position, etc. would be very helpful. As basic a possible explanation would be great, since I am very new:)

Also, any suggestions for best practice (e.g. if I should do something in a different way would be very helpful).

Thanks ever so much!

I would use a TextAsset rather than System.IO if possible.

Here's an example that takes a comma delimited file and stores the numbers it finds in an array:

/*
 * To create a TextAsset, create a text 
 * file and drag it into your Unity project 
 *
 * (somewhere in your assets folder)
 *
 */

var myTextFile  :  TextAsset;

function processTextFile ()
{

    /* create an array to store the floats we find in the file */

    var floatArray = new Array();

    /* split the text file by newline characters */

    var lineArray : String [] = myTextFile.text.Split("
"[0]);

    /* loop over each line in the file */

    for ( var thisLine : String in lineArray ) {

        /* split each line by commas */

        var numberStrings : String [] = thisLine.Split(","[0]);

        /* loop over the numbers in this line */

        for ( var thisNumber : String in numberStrings ) {

            /* parse the string into a float */

            var someFloat : float = float.Parse(thisNumber);

            print("Found this float: " + someFloat);

            /* put the float into an array you can use later */

            floatArray.Push(someFloat);
        }
    }

    print("I found " + floatArray.length " + numbers: ");

    for ( var i = 0; i < floatArray.length; i ++ ) {
        print(floatArray*);*
 *}*
 _/* convert the array to a builtin array for fun */_
 *var fastFloatArray : float [] = floatArray.ToBuiltin(float);* 
*}*
*```*

Thanks ever so much! I have tried this but nothing seems to be processing, so I am not sure what I’ve done wrong.

  1. I’ve created a .txt file (with a series numbers delimited by commas (1,2,3,4,5 etc) and dragged the textfile into Unity Assets
  2. I’ve attached the code you supplied to a game object (removed this bit: " + numbers: " )
  3. I’ve dragged the .txt file into the My Text File field in the inspector

when I hit play, nothing appears in the console. Any ideas on what I have done wrong?

Thanks for all of your help.