hmmm, I’ve been trying to solve this for three nights now and still no luck. Admittedly I’m still very much learning so have no idea what I’m doing. zine92’s suggestion may have done the trick, but I’m not too sure if I fully understand how to implement it (I thought I did, but now I’m not so sure.)
I have this code on an empty game object, which works fine:
public final var MAX_SPACEMEN = 200 ;
public final var AREA_SPAWNED_IN = 200;
function Start(){
CreateInitialSpacemen();
SpawnPrefab("p_player", 2,2,0 );
SpawnPrefab("p_camera",0,0,-10);
}
static function SpawnPrefab(prefabName : String, posX, posY, posZ ) {
var localPath : String = "Assets/GalacticRescue/Prefabs/" + prefabName + ".prefab";
var obj = (AssetDatabase.LoadAssetAtPath(localPath, GameObject));
Instantiate (obj, Vector3(posX, posY, posZ), Quaternion.identity);
}
function CreateInitialSpacemen(){
for(var i=0; i<MAX_SPACEMEN; i++){
SpawnGameAssetAtRandomXY("p_spaceMan", 10);
}
}
function SpawnGameAssetAtRandomXY(assetName, rangeValue : float){
var gameAsset : String = "Assets/GalacticRescue/Prefabs/" + assetName + ".prefab";
var loadedGameAsset = (AssetDatabase.LoadAssetAtPath(gameAsset, GameObject));
Instantiate (loadedGameAsset, Vector3(Random.Range(-rangeValue, rangeValue),(Random.Range(0, -AREA_SPAWNED_IN)),0), Quaternion.identity);
}
And I have this code running on the spawned game asset (p_spaceMan):
function OnTriggerEnter (other:Collider) {
this.transform.parent = (GameObject.Find("GR_ShipRotate").transform);
Debug.Log ("Object Linked", gameObject);
}
But when I run the scene, a random number of p_spaceMan assets are immediately linked to GR_ShipRotate, even though they’re no where near the parent collider.
Anyone able to help? I’m pulling my hair out.