I'm still having difficulty with instantiated prefabs. I've made a small star map to see if I can change a variable on an individual prefab but I seem to have hit a brick wall. The following scripts show no errors but the debug.log fails to print anything. The first script is the clone manager which is attached to an empty game object in the hierarchy, the second is attached to the prefab.
StarGenScript:
var BasicStarPrefab:GameObject; // The prefab I am cloning
var CloneScript:BasicStarScript; // The script that should be attached to each clone
var StarGenScript:StarGenScript; // The clone managers script
//The basic attributes of each star
static var XCurrentStar;
static var YCurrentStar;
static var ZCurrentStar;
static var CurrentStarType;
static var CurrentStarNumber;
// Call this function once at the start
function Awake () {
StarGenerate();
}
function StarGenerate (){
for (var CountNum : int = 0;CountNum < 1000; CountNum++) {
// Randomly determine the position of each star
XCurrentStar = Random.Range(0.0, 10.0);
YCurrentStar = Random.Range(0.0, 10.0);
ZCurrentStar = Random.Range(0.0, 10.0);
// Set the identification number and type of star
CurrentStarNumber = CountNum;
CurrentStarType = Random.Range(1, 2);
// Make a vector of the random coordiantes and instantiate a star
var position = Vector3(XCurrentStar,YCurrentStar,ZCurrentStar);
var NewBasicStarPrefab = Instantiate(BasicStarPrefab, position, Quaternion.identity);
NewBasicStarPrefab.name = "BasicStar"; // Rename the clone to BasicStar
// Access the clones script and send some variables to it
CloneScript = NewBasicStarPrefab.GetComponent(BasicStarScript);
CloneScript.StarNumber = StarGenScript.CurrentStarNumber;
CloneScript.StarType = StarGenScript.CurrentStarType;
}
}
BasicStarScript:
static var StarType;
static var StarNumber;
function Update () {
Debug.Log(StarNumber);
Debug.Log(StarType);
if(StarType==1){
renderer.material.color = Color.black;
}
if(StarType==2){
renderer.material.color = Color.white;
}
}
If someone could fix these scripts and post a working pair I would be eternally grateful