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 MagnusZane · Mar 08, 2012 at 04:43 PM · gameobjectarraysfoldergetdirectories

Get GameObject array from folder

I need to find a way to create a game object array in JS from a folder containing models and prefabs. is there any way to accomplish this?

to be more precise,

need a way to load ALL game objects from the folder without necessarily knowing what their names are..... is there any way to do this(after building)???

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
0

Answer by MagnusZane · Mar 13, 2012 at 04:20 PM

I found the solution. you have to convert the array to a builtin array every time you want to add/Remove an object. i'll post an example:

 //*******************************************//
 //***************Created by Eddy*************//
 //******************************************//
 
 var Contents:Transform[];
 //Although in the demo I am going to identify items as its own script *Item* I will still
 //identify and add them by thier transform to allow more of a versitile of ways to program a game
 //using this simple type of script :P.
 
 
 function AddItem(Item:Transform){//Add an item to the inventory.
     var newContents=new Array(Contents);
     newContents.Add(Item);
     Debug.Log(Item.name+" Has been added to inventroy");
     Contents=newContents.ToBuiltin(Transform);// array to unity builtin array
 }
 function RemoveItem(Item:Transform){//Removed an item from the inventory.
     var newContents=new Array(Contents);
     var index=0;
     var shouldend=false;
     for(var i:Transform in newContents){
         if(i==Item){
             Debug.Log(Item.name+" Has been removed from inventroy");
             newContents.RemoveAt(index);
             shouldend=true;
             //No need to continue running through the loop since we found our item.
         }
         index++;//keep track of what index the item is and remove it.
         if(shouldend){
             Contents=newContents.ToBuiltin(Transform);
             return;
         }
     }
 }
 
 function Start(){
 var rsources=new Array(Resources.LoadAll("RPGOBJ", Transform));
 Contents = rsources;
 }

all credit goes to eddy for his inventory example.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

odd error in c# script when working with arrays 2 Answers

Need help with assigning game objects to variable 2 Answers

How can I get every other GameObject except for the one I'm using? 1 Answer

Three Spots For Three Random Objects 1 Answer

Cannot find the length of an array 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