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:
I want to run this scripts only one time, in the initialization of the game. how can I do it?
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).
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.