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 Al-Anselmo · Jan 24, 2011 at 06:46 AM · instantiatearrayaccesscollection

How to access Instantiated gameObjects from a Collection inside for loop?

I have 3 prefabs named "blackout" being instantiated in the position of other 3 gameObjects I positioned and rotated myself in the editor. This works fine.

However, after the 3 blackouts are instantiated, I need to "set active to false" (disactivate) each one of them in an interval of 2 seconds between each one - starting from the first blackout - instantiated in the position of blackoutCollection[0] - until the last and third blackout - positioned in blackoutCollection[2].

How can I do this? I'm failing to access the blackout gameObjects. blackoutCollection[i] are only empty gameObjects used to place the blackout prefabs where I want.

function Blackout() { var i : int = 0;

 for (i=0; i<=2; i++)
 {
     Instantiate (blackout,
     Vector3 (blackoutCollection[i].transform.position.x,
         blackoutCollection[i].transform.position.y,
         blackoutCollection[i].transform.position.z),
     blackoutCollection[i].transform.rotation);
 }

 yield WaitForSeconds(2);
 blackoutCollection[0].gameObject.active = false;
 // Lines like the above represent what I have,
 // but I don't need to disactivate those empty gameObjects.
 // I need to do this with the blackout prefabs.

 yield WaitForSeconds(2);
 blackoutCollection[1].gameObject.active = false;

 yield WaitForSeconds(2);
 blackoutCollection[2].gameObject.active = false;

}

I tryied using blackout.blackoutCollection[1].gameObject.active = false; but of course that didn't work.

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

1 Reply

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

Answer by mrde · Jan 24, 2011 at 07:32 AM

you can each instantiated prefabs set child your 3 position gameobject (blackoutCollection[i])

try follow. not checked

for (i=0; i<=2; i++) {

// add this var instObj = Instantiate (blackout,

 Vector3 (blackoutCollection[i].transform.position.x,
     blackoutCollection[i].transform.position.y,
     blackoutCollection[i].transform.position.z),
 blackoutCollection[i].transform.rotation);
 // add this
 instObj.parent = blackoutCollection[i].transform;

}

and instead

blackoutCollection[1].gameObject.active = false;

call

blackoutCollection[1].gameObject.SetActiveRecursively(false);

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 Al-Anselmo · Jan 24, 2011 at 06:53 PM 0
Share

Thank you! This worked perfectly.

The only thing that was missing was the "transform.parent": instObj.transform.parent = blackoutCollection[i].transform;

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

No one has followed this question yet.

Related Questions

Make object move in a direction depending on where it spawns? (C#) 1 Answer

Different array value at different times 1 Answer

Prefabs instantiated from an array are keeping their public int value 1 Answer

How Do I Add An Instantiated Object To An Array? 3 Answers

Finding the Sum of Values of Multiple GameObjects in an Array + Variable Sized arrays 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