Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 wallstreet · Nov 04, 2015 at 12:57 PM · leveltxt

generating a 4x5 tile map using unity c#

Im trying to create a 4x5 tile map using a text.txt file but i cant figure it out i have tried everything and legit nothing has worked. i found many examples but they dont explain how to do it its more just a solution . i really need help with this if somone can give me some information . maybe even a sample script just so i can fully understand

what i want to do is have a txt file with

11111

32134

11132

21413

something like that and using that it creates the prefab assigned to that number and they are right next to each square. please help

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by HenryStrattonFW · Nov 05, 2015 at 12:07 PM

well the first thing to do here is to read that file in so that its easily readable. First thing I would suggest is splitting each number with a comma or other delimiter character (for example i often see the pipe | used in place of comas for delimeters). So your file would look like this.

 1,1,1,1,1
 3,2,1,3,4
 1,1,1,3,2
 2,1,4,1,3

You could then read this into a string[] using System.IO.File.ReadAllLines() so now you have each line of the file as a string. You can then iterate over these strings and with each one do the following.

  • Split the string with your delimeter (in this case ',') using string.split()

  • Iterate over that resulting array.

  • For each item in THAT array, parse the value to an int (if necessary) and use it to load the appropriate prefab.

If your text file is an asset in the build then you can even connect it to your script in the inspector as a TextAsset and use TextAsset.text to read it in (if you do this, you will need to split with the '\n' character which should give you the same result as reading each line with the ReadAllLines method.

Hope this helps a bit.

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Character Loading Location 2 Answers

Anyway to save which seen the player was on, then load that scene back from another one at a different time? 2 Answers

Level selection from main menu? 4 Answers

Need help with a Main Menu 1 Answer

Score / Loading Level 2 Answers


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