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!