Making a doodle jump platvorm spawner

Hi Everybody

So I am trying make a doodle jump platform spawner that would spawn different types of platforms from an array.
The idea is, that I will make an arry and add plaforms to it and depending on the player progress in the game will activate different parts of the array to generate difficulty.

Lets say i have 100 array items. 0-7 are the same item - basicPlatform and 8-9 are moving platforms.
So if use Range.Range (0, 9) I get every 5th moving platfrom making a pretty easy experience.
At later stages I pick another range with different platforms in it.
Here is what I made:

var yCurrent : int;
var Range : int;
var basicPlatformPrefab : GameObject;
var brakingmovingPlatformPrefab : GameObject;
var brakingPlatformPrefab : GameObject;
var Player : GameObject;
private var spawnableObject : GameObject;

var plaformBox = Array(basicPlatformPrefab, brakingPlatformPrefab, brakingmovingPlatformPrefab);

function Update()
{
	yCurrent = Player.transform.position.y - gameObject.transform.position.y;
	if (yCurrent > -100 )
	{
		var spawnableObject = platformBox[Random.Range(0, platformBox.length)];
		spawnableObject.transform.position.x = Random.Range(-8,8);
		Instantiate(spawnableObject, spawnableObject.transform.position, spawnableObject.transform.rotation);
		spawnableObject.transform.position.y = spawnableObject.transform.position.y + Random.Range(2,4);

	}
}

And here is the error that I get:
Assets/Scripts/spawner.js(18,39): BCE0005: Unknown identifier: ‘platformBox’.

Its about this line:
var spawnableObject = platformBox[Random.Range(0, platformBox.length)];

Basically the way I understand it is that an Array is not a game object and I cant Insantiate directly using

var plaformBox = Array(basicPlatformPrefab, brakingPlatformPrefab, brakingmovingPlatformPrefab);

function Update()
{
	yCurrent = Player.transform.position.y - gameObject.transform.position.y;
	if (yCurrent > -100 )
	{
		patformBox.transform.position.x = Random.Range(-8,8);
		Instantiate(patformBox, patformBox.transform.position, patformBox.transform.rotation);
		patformBox.transform.position.y = patformBox.transform.position.y + Random.Range(2,4);
	}
}

Hence I made the var spawnable object that I randomise on every update that is stated as a gameobject, but I seem to be missing some thing…

Thanks in advance for the input!

You can not spawn an array per say, it is not a game object. It is, not a Class. You can however spawn a member of an array.

first, Random.Range(0,9) will never get you a platform #9, because the upper int is not inclusive. So only 1 platform out of 8 would be moving :wink:

second, you got the “Unknown identifier: ‘platformBox’” error because you have a typo in array creation - var plaformBox is missing a “t”. Use autocomplete more often to avoid typos.

Hi, could you elaborate a bit on that in the context of my code.
The way I understand what you are saying is:

var yCurrent : int;
var Range : int;
var basicPlatformPrefab : GameObject;
var brakingmovingPlatformPrefab : GameObject;
var brakingPlatformPrefab : GameObject;
var Player : GameObject;
private var spawnableObject : GameObject;

var platformBox = Array(basicPlatformPrefab, brakingPlatformPrefab, brakingmovingPlatformPrefab);
var platfromBox : GameObject[];

function Update()
{
	yCurrent = Player.transform.position.y - gameObject.transform.position.y;
	if (yCurrent > -100 )
	{
		var spawnableObject = platformBox[Random.Range(0, platformBox.length)];
		GameObject.transform.position.x = Random.Range(-8,8);
		Instantiate(platformBox[Random.Range(0, platformBox.length)], gameObject.transform.position, gameObject.transform.rotation);
		gameObject.transform.position.y = gameObject.transform.position.y + Random.Range(2,4);
	}
}

… which oddly “works” and by works I mean the code gets compiled and game starts running, but it does not produce any platforms and there is this:
NullReferenceException
spawner.Update () (at Assets/Scripts/spawner.js:20)

…and I do have platformes assigned to the spawner.
Am I supposed to create a temporary variable (spawnableObject in my case) under update or how does that work?
I was currently using it, because I thought this would provide me with a way to output a gameObject to Unity but stating:

var spawnableObject = platformBox[Random.RanIge(0, platformBox.length)];

and so I could use:

spawnableObject.transform.position.x = Random.Range(-8,8);
		Instantiate(spawnableObject, spawnableObject.transform.position, spawnableObject.transform.rotation);
		spawnableObject.transform.position.y = spawnableObject.transform.position.y + Random.Range(2,4);
	}

Thanks a lot for your patience!

A simple example that works:

var platformBox = new Transform[3]; 


function Start()

{       
     var platformprefab = platformBox[Random.Range(0, platformBox.length)];
      
     var new_platform = Instantiate(platformprefab, gameObject.transform.position, gameObject.transform.rotation) as GameObject;

     new_platform.transform.position.y = new_platform.transform.position.y + Random.Range(2,4);
 }