• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sonic220 · Sep 03, 2013 at 08:59 AM · filepersistent

Include .txt files in build

Hi guys, I'm making a game where maps are saved in specific folders with .txt files. I want the files to be included in the build ( the game is for android ) so that when the user install my app, the files are already there to be read. There is a path that I can use? Is it possible?

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image $$anonymous$$ · Sep 03, 2013 at 09:08 AM 0
Share

I don't know about android but yeah you can have txt files in your build, they are saved as TextAsset, you can reference them as TextAsset component when reading. You can put them also inside Resources folder for quicker loading.

avatar image sonic220 · Sep 03, 2013 at 09:34 AM 0
Share

So, I'll just use Application.dataPath and then + "/Resource" to locate my file?

avatar image $$anonymous$$ · Sep 03, 2013 at 09:38 AM 0
Share

No you can use directly ResourceLoad as exlained here:

http://docs.unity3d.com/Documentation/ScriptReference/Resources.Load.html

Every asset you put there can be loaded with a single line, and is forcely included in the game build.

But if you don't want to use Resources folder, then yeah you have to use Application.dataPath, the only thing I don't know if Application.dataPath would work on Android, for this you have to wait an answer of someone more competent on mobile.

avatar image sonic220 · Sep 03, 2013 at 09:47 AM 0
Share

By getting a textAssets I'm not quite sure how to read it, for now I'm using this: filePath = Application.dataPath + Path.DirectorySeparatorChar + filePath + Path.DirectorySeparatorChar; var val : int; var line : String; if (System.IO.File.Exists(filePath + fileName1)) { var sRead = new File.OpenText(filePath + fileName1); line = sRead.ReadLine(); while(line != null){ val = int.Parse(line); timeVector1.Add(val); line = sRead.ReadLine(); } sRead.Close(); }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Paulius-Liekis · Sep 04, 2013 at 08:13 PM

Text files can be referenced in scripts as TextAsset. Then you can simply get contents of it in your script.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to change the file name for the final build? 2 Answers

WHY WONT IT WORK? 1 Answer

How does a TextAsset work? 1 Answer

How to get info from a text file 1 Answer

Mobile File Directory. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges