Search Unity

Accesing local files

Discussion in 'Scripting' started by ratamorph, Mar 28, 2008.

  1. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Hey guys anyone know how to access a local file? say a texture, a text file, a video, etc.
    I know the www class does these things for remote files but what about local files?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    prepend file:// when using the WWW class or use .NET's System.IO classes.
    (File access is disabled in the web player of course)
     
  3. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Nice that makes things simple, is there a way to know from code if I´m running a web player or a standalone?
     
  4. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I tried loading a local texture and it did work, however if I put that texture in a folder, it stops working.

    var www : WWW = new WWW ("file://C2logo.png");

    this one works if C2logo is in the same folder as assets, library and temp(ie root project folder).

    var www : WWW = new WWW ("file://a/C2logo.png");

    If I move C2Logo to a folder named "a" inside the same folder as assets, library and temp, it does not work.

    Any ideas?
     
  5. nebulousecho

    nebulousecho

    Joined:
    Jan 23, 2008
    Posts:
    23
    Just from having been making websites since I was about 12, I assume if you place a file anywhere other than in the folder you are working from, you need to supply the exact location of the file. Such as: file:///Applications/Unity/FolderThatWasCreated/file.png
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Check out the docs for the Application class (particularly dataPath and platform).

    --Eric