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 NGKrush1 · Jun 14, 2012 at 11:13 AM · c#instantiate3dtext3d text

instantiate 3d text with different names - c#

Hi,

I have a List of strings all with a different name.

For each string I'm instantiating 3dtext that needs to take each List entry's name as it's own.

I have it working for the most part, but my 3dtext will only take the name of the last. I'm nearly positive it has something to do that my code gives the same name to each instance of the 3dtext, but have no clue how to solve this. itemsTwo = my list. it will constantly have a different amount of objects with different names in them.

 foreach (string s in itemsTwo)
         {
             Vector3 positionItemButton = new Vector3(0, posY, 0);
             Vector3 rotationItemButton = new Vector3(90, 180, 0);
             Vector3 rotationText = new Vector3(180, 180, 180);
             Instantiate(button, positionItemButton, Quaternion.Euler(rotationItemButton));

             //set public text to List contents, so prefab can use it.
             itemName = s;
 
             //instantiate prefab
             Instantiate(buttonText, positionItemButton, Quaternion.Euler(rotationText));

             posY = posY - 2.0f;

         }

and the prefab has this as code (in Start):

 if (name != null)
     {
         name = itemLocation.Instance.itemName;
         (gameObject.GetComponent(typeof(TextMesh)) as TextMesh).text = name;
     }

so right now I am getting X number of 3dtext all with the same name. any ideas on how to reach each string seperately?

Comment
Add comment · Show 1
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 flamy · Jun 14, 2012 at 11:16 AM 0
Share

that is because the variable name is same for all the instances....

or are u changing the name somewhere??

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by whydoidoit · Jun 14, 2012 at 11:19 AM

Well either actually rename in Awake() - so it actually happens during the Instantiate call:

Or even better - create a generic list of them:

     public static List<TextMesh> texts = new List<TextMesh>();
     ....

      var x = Instantiate(buttonText, positionItemButton, Quaternion.Euler(rotationText)) as WhateverButtonTextPrefabIsDefinedAs;
      texts.Add(x.GetComponent<TextMesh>());

Now you can access them using the array:

     YourScriptName.texts[2].text = "blah";
Comment
Add comment · Show 1 · 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 whydoidoit · Jun 14, 2012 at 11:19 AM 0
Share

Oh yeah - probably don't check for the name being null too!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Instatiating a prefab in a random position 0 Answers

Issue Instantiating prefab in C# 0 Answers

Missing (Game Object) 3 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