Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 orenko · Sep 05, 2016 at 01:31 PM · scripting problemscripting beginnerprefabsscriptingbasics

creating and using list of prefabs

hello, I have a scripts that create some new prefabs and store them in AssetDatabase, and also in a list of gameObjects. I have two questions: 1. I want to run this scripts only one time, in the initialization of the game. how can I do it? 2. I have a script that is called later during the game, and in this scripts I want to use the prefabs from the first scripts. (I want to take the list of all the prefabs created).

Can someone help - how can I do it?

Thanks

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Madrig88 · Sep 05, 2016 at 06:12 PM

One way you can attempt this is by using a global variable in your Database script, and then forwarding a variable from another script. Here is how I would do this...

AssetDBScript:

 // Add global variables to be modified elsewhere.
 
 static var prefab1 : GameObject;
 static var prefab2 : GameObject;
 
 //etc....

Then when you are ready to start the game, use this script to modify the global variable in the AssetDBScript.

 #pragma strict
 
 // Prefab variable names
 
 public var prefabName1 : GameObject;
 public var prefabName2 : GameObject;
 // etc...
 
 function Start () {
     // On start, apply variable.
     
     AssetDBScript.prefab1 = prefabName1;
     AssetDBScript.prefab2 = prefabName2;
 
 }


When you are done with the script, you can add the prefab to the variable using the inspector.

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 orenko · Sep 06, 2016 at 09:10 AM 0
Share

Thanks! If I use this way, I didnt understand - how do I use the list I created in the scripts? I have around 80 prefabs so I must use the scripts. #pragma strict

  // Prefab variable names
  
  public List<GameObject> listOfPrefabs;
  
  // etc...
  
  function Start () {
      // On start, apply variable.
      
     //here , I need to use the script. let's call it generatePrefabs.
     //how it is  done? maybe somethong like:
      AssetDBScript.listOfPrefabs = prefabsGenerator.getList()
  
  }
avatar image
0

Answer by ItaloSouza · Sep 05, 2016 at 07:54 PM

Alternatively, you should look for the "Singleton Design pattern".

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 orenko · Sep 06, 2016 at 09:11 AM 0
Share

Thanks, but the same question as to the other reply remains - even if I create the singleton, I dont understand how to use it later, during the game?

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

Running scripts from editor 1 Answer

Counting prefabs in screen?,Problem with counting prefabs in screen 1 Answer

Need help fixing my script 1 Answer

How to add force if spherecast is true and how to set direction of sphere 0 Answers

How do I make a photography function? 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