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
1
Question by Vincent_soo · Dec 14, 2011 at 04:02 PM · array

how to push a Instantiate prefab to a array?

I figure and search about this problem but I just can't get a answer and decide to seek for help

I am trying to push a instantiate prefab to my array

This is my code:

 Instantiate(levelArray[levelInstanNum],Vector3(levelInstanX,-2.5,0),Quaternion.identity);
 levelArray.Push(levelArray[levelInstanNum]);

but then I found out that the Instantiate object will be object(clone) that why it can't push in to the array

Any idea how I can make

  levelArray.Push( Instantiate(levelArray[levelInstanNum],Vector3(levelInstanX,-2.5,0),Quaternion.identity));

I know maybe is quite basic, sorry... I am quite new in programming and hope to seek some guide here

Thank you

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 Anxo · Dec 14, 2011 at 04:24 PM 0
Share

how is the array declared? show the code you used to first create the array.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by flamy · Dec 14, 2011 at 04:36 PM

 var clone=Instantiate(levelArray[levelInstanNum],Vector3(levelInstanX,-2.5,0),Quaternion.identity);
 levelArray.Push(clone);

try this??

wat u actually did is adding the prefab to the array not the spawned gameObject..

if u r using c# change this a bit like

     Object clone = Instantiate(levelArray[levelInstanNum],Vector3(levelInstanX,-2.5,0),Quaternion.identity);
     levelArray.Push(clone);

i didnt try out the c# part though, it is jus a suggestion

Comment
Add comment · Show 2 · 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 Vincent_soo · Dec 15, 2011 at 04:55 AM 0
Share

Thank!!! it work like a charm~

avatar image Tasarran · Dec 15, 2011 at 05:20 AM 2
Share

Please click the check by the voting buttons to accept the answer :)

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

How to create an auido array (JavaScript) 1 Answer

NullReferenceException: Array C# 1 Answer

if collision.gameObject.tag == any of the elements in the array... 0 Answers

Can't get sound clip from array to play properly 1 Answer

I am attempting to build an array that houses 3 GameObjects 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