Problem , Help Me

I must use this script for read a name of a object from a text file and create the objecy that i had read at runtime … but there are some errrs , help me please …

import System.IO;
import System;
import System.Text;

private var enemy : GameObject;

function Start() {

   fileread("test.txt");
   enemy = Instantiate(Resources.Load("line", GameObject));
}



unction fileread (filename : String) {
   try {

      var sr = new StreamReader( Application.dataPath+"/"+filename);
 
      var line : String = sr.ReadLine();
      
      //print(line);
      return line;
      
      sr.Close();
      sr = null;

      }
      catch (e) {
         Debug.Log("internal error!");
         return null;
      }
}



function Update () {
   CreateEnemy();
}



function CreateEnemy() {

      var newEnemy = Instantiate(enemy, Vector3(0,0,0), Quaternion.identity);
	  	      
   }
}

Thank You …

Hi, hard to say as you didnt post any errors.

I have not much experience with streamreaders , but what I see, is that you return from your function without closing the stream.

Maybe this will work :

function fileread (filename : String) { 
   try { 

      var sr = new StreamReader( Application.dataPath+"/"+filename); 
  
      var line : String = sr.ReadLine(); 
      
      //print(line); 
      //return line; <--- not there
      
      sr.Close(); 
      sr = null; 
       
      return line ;   // but here

      } 
      catch (e) { 
         Debug.Log("internal error!"); 
         return null; 
      } 
}


oxl