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 /
  • Help Room /
avatar image
0
Question by sid4 · Oct 21, 2016 at 10:37 AM · script.

how do i reference a text file in script?

I need to make a reference to "list 1" which is my text file but I do not know how please help

c+ using UnityEngine; using System.Collections; using UnityEngine.UI;

       public class opena: MonoBehaviour {
 
         public GameObject inputField;
         public string wordsFile = "c:\\file.list1.txt"; // EDIT THIS TO POINT TO YOUR FILE OF 60,000 WORDS
 
            void Start() {
             inputField = GameObject.Find("InputField"); //This is where you assign the input field object so you can access your inputField component
             inputField.GetComponent < InputField > (wordsFile).text = "list1"; //This makes it so the input field starts with nothing in it.
 
             string[] array = File.ReadLines().ToArray(); // This will load a text file into an array of strings
                 var hash = new HashSet < string > (array); // this converts the string array to a HashSet, could also use a dictionary for slightly better speed
         }
 
         void Update() {
             if (Input.GetKeyDown(KeyCode.Return)) { // Check for if they have hit enter 
                  
                 string input = inputField.GetComponent < InputField > ().text; // set a string to be what they entered
 
                 if (hash.Contains(input)) // check if the HashSet contains the code they entered 
                 {
                           // If they get here the code is correct
                     // i.e its in the list of 60,000 words
                     // do SOMETHING
                 } else {
                     // IF they get here... then they entered a WRONG CODe
                          // i.e not in the list of 60k words
                     // DO SOMETHING
                 }
             }
         }
          }
 
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

0 Replies

· Add your reply
  • Sort: 

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

76 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

plz help me in Trivia Quiz Game Template setup 0 Answers

How to put the server to the player and client see be in the camera? 0 Answers

Loading Next Scene 2 Answers

CAMERAS ERROR , I NEED HELP 0 Answers

Use same scene with multiple difficutlt levels 0 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