I was testing my game and I realized that the stairs weren’t spawning. The titles are randomly generated and this script will run as soon as the title is spawned. It is supposed to create a stair case to make the player proceed. The bottom half is for spawning enemies. It may not be causing the problem but I don’t know. Thanks!
#pragma strict
var stairsSpawn : boolean = true;
var buriedAlive : GameObject;
var enemyNumber : float = 999;
var number : float;
var stairs : GameObject;
function Start () {
number = Random.Range(1,320);
if(number <= 12 && stairsSpawn == false) {
Instantiate(stairs,transform.position,transform.rotation);
stairsSpawn = false;
}
}
function OnTriggerEnter2D (obj : Collider2D) {
var name = obj.gameObject.name;
if(name == "Main Camera") {
print("camera");
enemyNumber = Random.Range(1,5);
if(number <= 10) {
if(enemyNumber <= 5) {
Instantiate(buriedAlive,transform.position,transform.rotation);
}
}
}
}
As ThermalFusion’s question points out, you don’t seem to be setting stairsSpawn to false at any point other than within code where stairsSpawn would have to already be false to get to (it’s unreachable since you’ve already set stairsSpawn to true up top). My guess, from the looks of what you’re doing, is that you need to change “stairsSpawn == false” to “stairsSpawn == true” on line 9. Not tested, but it would make sense as that seems to be where & when you want to spawn your stairs. Good luck!