Looking to make a working Array of Game Objects that can be used for spawn locations. I made an Array but I’m getting a error:
“NullReferenceException: Object reference not set to an instance of an object”
Which when clicked tell me that there is something wrong with this line of code:
instance = Instantiate(game_cube, arr[randomPick].position, arr[randomPick].rotation);
Here is my script:
private var arr : Array;
var game_cube : Rigidbody;
var cube_count = 0;
var walker0 : GameObject;
var walker1 : GameObject;
var walker2 : GameObject;
function Start () {
arr = new Array[3];
arr.Push(walker0);
arr.Push(walker1);
arr.Push(walker2);
}
InvokeRepeating("LaunchProjectile", 2, 3);
function Update() {
if (cube_count>= 10) {
CancelInvoke();
}
}
function LaunchProjectile () {
var randomPick : int = Random.Range(0,2);
instance = Instantiate(game_cube, arr[randomPick].position, arr[randomPick].rotation);
instance.velocity = Vector3.zero;
cube_count = cube_count +1;
}
Yes I think the answer is on the original thread. You needed Start or Awake to get it going. It should have given you compile errors.
– DaveA