I'm sure this is really to do, I just can't seem to find the best way around it. I have a "gateway" at the end of my level to go to the next level, but I don't want it "opening" until after the player has destroyed some cannons.
How do I create that gameObject so it is initially there at the start of the game?
I am using javascript to do this, and was hoping for some help. Thanks for your time
Use an if statement to check if all the cannons are destroyed before opening the gateway, like this:
var totalCannonsDestroyed = 0;
var destroyedCannonGoal = 5;
var gatePrefab : Transform;
function Start() {
gatePrefab.active = false;
}
function Update() {
if (totalCannonsDestroyed >= destroyedCannonGoal) {
OpenGate();
totalCannonsDestroyed = 0;
}
}
function OpenGate() {
gatePrefab.active= true;
}
This script needs to go on a "LevelManager" object.
var levelToLoad = 2;
function OnTriggerEnter(other : Collider) {
if (other.gameObject.CompareTag("Player")) {
Application.LoadLevel(levelToLoad);
}
}
This script needs to go on a gate object that you want to activate when enough cannons are destroyed. It should have a collider set to Trigger on it. You'll also want some way to keep track of the next level to load. This gameObject should be disabled by default. (The little checkbox near the object's name in the Inspector panel should not be checked)
Please note that the above code is untested and may contain errors.
Where `OpenGate()` is the function that allows your player to access the new level. You'll want to increase `totalCannonsDestroyed` by 1 every time you destroy a cannon, or else your gateway will never open.