In my game, I have two scripts that talk to each other. when a staircase is reached in the game, the first script destroys all but a few objects, and resets the character position. The other script re generates the level by placing a new room spawner at the origin point, which has it’s own script to generate the level. The objects get destroyed when the staircase is reached, but a new room spawner isn’t generated.
this is the first code:
void OnTriggerEnter(Collider col){
if(col.gameObject.tag=="Finish" && overseer.floors<60){
Debug.Log ("colliding");
GameObject[] name1=GameObject.FindGameObjectsWithTag("room");
GameObject[] name2=GameObject.FindGameObjectsWithTag("environment");
GameObject[] name3=GameObject.FindGameObjectsWithTag("Trap");
GameObject[] name4=GameObject.FindGameObjectsWithTag("Path");
GameObject[] name5=GameObject.FindGameObjectsWithTag("Spawn");
GameObject[] name6=GameObject.FindGameObjectsWithTag("Dig");
foreach(GameObject room in name1){
Destroy(room);
}
foreach(GameObject environment in name2){
Destroy(environment);
}
foreach(GameObject Trap in name3){
Destroy(Trap);
}
foreach(GameObject Path in name4){
Destroy(Path);
}
foreach(GameObject Spawn in name5){
Destroy(Spawn);
}
foreach(GameObject Dig in name6){
Destroy(Dig);
}
Destroy(GameObject.FindWithTag("Finish"));
endPos = initialPosition;
transform.position=initialPosition;
transform.rotation=initialRotation;
overseer.floors++;
overseer.maxtiles=0;
overseer.maxwalls=0;
overseer.nextfloor=true;
}
}
}
and the second code:
using UnityEngine;
using System.Collections;
public class overseer : MonoBehaviour {
public static int maxtiles;
public static int maxwalls;
public GameObject stairs;
public static float floors;
public static bool nextfloor;
public GameObject spawn;
public Transform masterLoc;
void Start () {
maxtiles=0;
maxwalls=0;
nextfloor=false;
StartCoroutine(mycoroutine());
}
IEnumerator mycoroutine(){
yield return new WaitForSeconds(1);
stairdig();
}
void stairdig(){
if(floors<60){
GameObject[] StairPosition;
StairPosition=GameObject.FindGameObjectsWithTag("room");
var StairPlace=Random.Range(0, StairPosition.Length-1);
Transform target = StairPosition[StairPlace].transform;
Instantiate (stairs, target.position, target.rotation);
Destroy(StairPosition[StairPlace]);
}
}
void update(){
if(nextfloor==true){
Instantiate (spawn, transform.position,transform.rotation);
}
}
}
I’m not sure what i’m doing wrong here. Any help would be appreciated.
well... now I feel kinda stupid. Thanks for the help :D
– sullivanshaddon't worry we've all done that at some point. glad i could be of help.
– Fornoreason1000