Search Unity

Reading text asset files - newbie

Discussion in 'Scripting' started by d@mmi, May 1, 2008.

  1. d@mmi

    d@mmi

    Joined:
    Nov 30, 2007
    Posts:
    19
    Hi

    I want to read an existing (x,y,z,var) data file into an array at start up. I have imported it as a Text Asset already. I've tried exposing a TextAsset type of variable in the script that I want to read it with but can't drop my Text Asset onto that.

    Any pointers gratefully received.

    Thanks

    Dave
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The text asset has some kind of extension that allows it to be read as text? (Usually ".txt".) Because if not it will behave as you describe.

    --Eric
     
  3. d@mmi

    d@mmi

    Joined:
    Nov 30, 2007
    Posts:
    19
    Thanks for advice. Working now.
     
  4. d@mmi

    d@mmi

    Joined:
    Nov 30, 2007
    Posts:
    19
    Got my text in, split it up nicely, got it into the arrays I want but can't convert my text strings into numbers and none of the usual JS conversion tricks work.

    I'm sure this is something simple but can;t find it anywhere.

    Help much appreciated as ever.
     
  5. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Try:
    Code (csharp):
    1. var myInt = System.Convert.ToInt32("123");
    Cheers,
    -Jon
     
  6. d@mmi

    d@mmi

    Joined:
    Nov 30, 2007
    Posts:
    19
    That's fantastic Jon - thanks.

    Is there a similar fix for non integers?

    Sorry = got it - toDecimal or toDouble