Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 artistshc · Apr 14, 2015 at 11:01 PM · characterswords

Setting Letter Tile Objects to their Char or String Equivalent

Hi there. I have a letter tile for each letter in the alphabet. I am doing a hangman-type game and I am trying to take a work (in the example below the word is "books") and convert each letter to a gameobject tile. I convert the word to an array of characters. I tried doing the following and I am getting null returns in the Debug.Log. Any ideas? Thanks.

 //we also want to know what the tile is by accessing the TileManager
     public GameObject A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
     //Object[] with all the tiles
     private GameObject[] tilesAll;
     //Object[] with only word tiles
     private GameObject[] tilesWord;
     string str = "Books";
     char[] wordAsChars;
     
 
     // Use this for initialization
     void Start () {
         //populating letter tiles into the tiles array
         tilesAll = new GameObject[] {A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z};
         //convert word string into an array of separate characters
         wordAsChars = str.ToCharArray(0, str.Length);
         //create space for the array 
         tilesWord = new GameObject[str.Length];
         //populating only word's letter tiles into this array
         for(int i=0; i<wordAsChars.Length; i++){
             //each letter is converted to a string so it can be used in GameObject.Find
             string letter = "" + wordAsChars[i];
             //find the gameobject that is of the same letter
             tilesWord[i] = GameObject.Find(letter);
         }
         
     }




Thank you in advance for any help. I am new to Unity...so I apologize if I did anything stupid. Be kind and don't tease me too much.

Thank you. Rachel

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Olgo · Apr 14, 2015 at 11:24 PM

Not sure where you are putting your Debug.Log to get a null reference exception. However, I tested your variables with a Debug.Log and everything seems to work except for tilesWord[i]. The reason for this would be because these GameObjects dont exist yet.

Do you have prefabs created for each letter yet? Do you have them assigned to this script in the inspector?

You could load them each one by one with Resources.Load or you could drag and drop them in the inspector.

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

Answer by artistshc · Apr 15, 2015 at 06:33 AM

Thank you so much for taking the time to answer. It landed up the reason that it wasn't working was because I needed to capitalize all the letters in string str = "Books"; (to BOOKS) because all the object tiles were capitalized. Thank you for helping!

Rachel

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Fighting game with 2 characters and be able to change character 1 Answer

Character Selection Scene Help 1 Answer

How do i make my character not fall through the ground 2 Answers

How to create multiple Characters? 2 Answers

iOS: Game Center show leaderboard with only my score ? 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