Search Unity

Stop resource load

Discussion in 'Scripting' started by Dual II, Feb 24, 2010.

  1. Dual II

    Dual II

    Joined:
    Feb 22, 2010
    Posts:
    23
    When i load an instance with : UnityEngine.Resources.Load unity load infinite clone of the object.
    How to stop the load of the object?

    This is the code:
    Code (csharp):
    1.  
    2. function Start() {
    3.    var oggetto = new Array();
    4.    oggetto = fileread("hero.txt");
    5.    var i : int = 0;
    6.    print((oggetto.length)-1);
    7.    while(oggetto.length!=i+1){
    8.    print(oggetto[i]);
    9.       enemy = Instantiate(UnityEngine.Resources.Load(oggetto[i]));
    10.       //enemy = Instantiate(UnityEngine.Resources.Load(oggetto[i],GameObject));
    11.       i++;
    12.       if(oggetto.length==i)
    13.         break;
    14.       }
    15.       enemy = null;
    16.       DestroyImmediate(enemy);
    17. }
    18.  
    I try with enemy=null and with destroy, and this stop the loading of the objet, but unity continue to try to load the null object and return "Null Reference Expection..."

    Thank you! =)
     
  2. Dual II

    Dual II

    Joined:
    Feb 22, 2010
    Posts:
    23
    Ok, resolved:

    i edit the function CreateEnemy()

    Code (csharp):
    1.  
    2. function CreateEnemy() {
    3.       if(oggetto.length!=j+1){
    4.       var newEnemy = Instantiate(enemy, Vector3(0,0,0), Quaternion.identity);
    5.       }              
    6. }
    7.