Unity Spain

Post Antiguos => General (Antiguo) => Mensaje iniciado por: maya111 en Agosto 12, 2015, 10:40:04 PM

Título: duda de Script array
Publicado por: maya111 en Agosto 12, 2015, 10:40:04 PM

                   public class Coordinates : MonoBehaviour {
    private string[] Names;//si la variable es privada no se agrega :D en la interfaz de Unity
    private Vector3[] Locations;
    string filepath = "./example2.txt"; //This is the path of the text file
    
    
    float inc=600000000f;
    // This gets all the locations from the file
    void Update () {  
        string[] filelines = File.ReadAllLines(filepath);
        Names = new string[filelines.Length];
        Locations = new Vector3[filelines.Length];
        
        for(int i = 0; i < filelines.Length; i++)
        {
            string[] parts = filelines.Split("/"[0]);
            Names = parts[0];
            string coords = parts[1].Substring(1,parts[1].Length-2);
            string[] coord = coords.Split(","[0]);
            float coord0 = float.Parse(coord[0]);
            float coord1 = float.Parse(coord[1]);
            float coord2 = float.Parse(coord[2]);
            Locations = new Vector3(coord0, coord1, coord2)* inc * Time.deltaTime;
            Debug.Log(Names + " : " + Locations.ToString());//el debug manda a consola 
        }
        
        //transform.position =Locations[0];
        //print(transform.position.x);
        Vector3 var ;
        for(int i = 0; i < filelines.Length; i++)//recorrido del arreglo para sacar el tamaño solo filelines
        {
            //StartCoroutine(MyMethod());
            var= Locations;
            //print ("Hola\n");
            transform.position =var;
            
            //SleepTimeout(5);
            //print(transform.position.x);
            for (int j=0; j<500; j++);
            
            
        }
        
        
    }
Hola una ves más, pero necesito ayuda no se que estoy haciendo mal en mi script ya que tengo esto:      y en la linea que esta en negritas me marca el siguiente error:IndexOutOfRangeException: Array index is out of range.
Coordinates.Update () (at Assets/Coordinates.cs:26)alguien me podria ayudar?? Gracias. 
Título: duda de Script array
Publicado por: iRobb en Agosto 12, 2015, 10:50:41 PM
Diría que:
parts[1].Length-2
Es menor de 1.