Search Unity

Help me convert this starfield script please.

Discussion in 'Scripting' started by San_Holo, Mar 10, 2015.

  1. San_Holo

    San_Holo

    Joined:
    Sep 26, 2014
    Posts:
    152
    EDIT, used something else in the end.
     
    Last edited: Mar 12, 2015
  2. San_Holo

    San_Holo

    Joined:
    Sep 26, 2014
    Posts:
    152
    I do have a 'Resources' directory with the textures in waiting to load btw.
     
  3. San_Holo

    San_Holo

    Joined:
    Sep 26, 2014
    Posts:
    152
    I should email the chap... is he instantiating those stars or drawing them via draw-texture...I simply don't know, I'll have to experiment
     
  4. Pysassin

    Pysassin

    Joined:
    Dec 27, 2012
    Posts:
    87
    I think the error is caused because the variable random is not getting set correctly. I noticed the only place in the given code it is called is OnStart which is notoriously buggy in Unity try moving the OnStart code to OnEnable and see if that helps the issue.
     
  5. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    What do you mean "Buggy"? OnStart isn't even a unity function anyway, it's just Start()
     
  6. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Your console output doesn't seem to be matching up with your script line numbers, and the errors look strange... Did you abbreviate them or something? Looks like it should be a Vector, but the output is cut off. Knowing that full line would help.

    Null Reference Exception means you're trying to access a variable that hasn't been set. The following lines should point you to where that's occurring, but that doesn't seem to jive with what I see in your script at those lines.

    Edit: Just saw your comment on the code creator's post. SpriteBatch is the XNA way of drawing your 2D assets as a batch (combined render calls) that doesn't exist as-is in Unity. I haven't done anything with 2D in Unity, so I don't know what the equivalent would be, but it may be worth reading about XNA and SpriteBatch to see how you can apply the principles of what it does to Unity.
     
    San_Holo likes this.
  7. San_Holo

    San_Holo

    Joined:
    Sep 26, 2014
    Posts:
    152
    Got ya, I didn't know what XNA was, slightly better informed now, there is more information HERE about this particular call but anyway I'll have to convert it seemingly, I'll have a crack at it, cheers