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 rakesh12 · Nov 16, 2012 at 04:42 AM · gameobject

How i instantiate button and name them.

How i instantiate 5 button by using 1 button and keep the name of button differently.can u suggest how it is possible.. hey i asked i have one game object called button, now i trying by using this gameobject i create 5 different game object and add different name using text script on this gameobject . if u further explain let me know.

Comment
Add comment · Show 9
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 sparkzbarca · Nov 16, 2012 at 05:10 AM 1
Share

you change the prefab then you instance.

 for (int x = 0; x < 5; x++)
 { 
   button.name = "button" + x.tostring;
   instantiate(button);
 }

there is now button 1, button 2, button 3, button 4 and button 5.

$$anonymous$$ark as answered please. :)

avatar image rakesh12 · Nov 16, 2012 at 06:00 AM 0
Share

thanks for ur help but i need more help i try to store name like play , start,stop, not button1,button2 like that can u suggest

avatar image sparkzbarca · Nov 16, 2012 at 06:06 AM 0
Share

make an array of strings

 names[0] = "Play"
 names[1] = "Start"
 
 for (int x = 0; x < 2; x++)
 { 
   button.name = names[x];
   instantiate(button);
 }

that will name the first button play and the second start

should be pretty easy to add more names :)

don't forget to mark as answered :)

avatar image rakesh12 · Nov 16, 2012 at 06:49 AM 0
Share

hey everything work well , but it not take the name of button.

avatar image sparkzbarca · Nov 16, 2012 at 07:32 AM 0
Share

hmmm? button.transform.name maybe? button.tag should definately work

An instance should copy button, I dont know why it wouldnt work :(

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · Nov 16, 2012 at 04:45 PM

Well try doing it after the fact. That and maybe it was an issue with not casting it. (something I recently learned about).

//technically i think instantiate makes an object an object //not a game object. Maybe this will fix is.

 public UIButton button;
 
 
 GameObject[] Buttons;
 
 Buttons = new GameObject[3];
 
 for(int x = 0; x < 3; x++)
 {
     Buttons[x] = instantiate(button) as GameObject;
 }
 
 Buttons[0].name = "play";
 Buttons[1].name = "pause";
 buttons[2].name = "rewind";
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 fafase · Nov 16, 2012 at 04:46 PM 0
Share

You might want to cap the I of Instantiate :) and it will tell you that parameters are missing I would think (position, rotation).

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

11 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

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Hi, getting error cs1041 in my code:identifier expected, "this" is a keyword; need solution please 3 Answers

How to move a gameObject without affecting its childrens' positions? 2 Answers

How do I replace the default Unity character Controller Model (ethans) with my own human model and still have all the functions of the character controller for ethans. 1 Answer

GameObject AddComponent and MonoBehaviour problem 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