Search Unity

What is the Problem with This Script :(

Discussion in 'Scripting' started by Yash987654321, Mar 30, 2015.

  1. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    I have a script which calls a function using Invoke which definds a array. The array uses another arrays Object.
    like
    LevelDeatils = new Object[] {
    O[0].......
    }



    Any Suggestions
     

    Attached Files:

    Last edited: Mar 30, 2015
  2. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    Its throwing a error Null Reference at line 82 -->
    LastObject = (Object) Instantiate (LevelDetails[(i-1)],SpawnPosition, Quaternion.identity);
     
  3. Acissathar

    Acissathar

    Joined:
    Jun 24, 2011
    Posts:
    677
    The very first iteration of your For Loop is trying to access LevelDetails[0-1] / LevelDetails[-1], and -1 is not a valid array index.
     
  4. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    Even with 0 it is not working
    :(
     
  5. Acissathar

    Acissathar

    Joined:
    Jun 24, 2011
    Posts:
    677
    It looks like you're trying to Invoke using LevelToDraw, but the string itself is never instantiated. You declare it, but since you never give it a string it defaults to null, which means that you never fill up your LevelDetails array.

    I'm just glancing over it in a text editor so I may be wrong
     
  6. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    No the problem is not with Invoke it is itself in Draw function's Institantinate line itself. :(:(
    or In the Definding Way of Array is incorrect
     
  7. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    Hey Hey! You are a geneious!
    I tried to call the function inside Awake and now it goes all correct..... So My problem is solved but why didnt the invoke statment worked? I made sure it is written properly in inspector..... Anyway I will use If instead of Invoke thank You a lot
    :D:D:D:D:D