- Home /
load level when no enemy car are left
I am making a car game were the player hits the cars and if all the cars die then it'll load a new level. I was thinking how about if all enemy cars die and a cube becomes activated so we then need to collide with it and a new level loads up. if you answer this question and it helps then ill give you a copy of the game for free.
Answer by FutchProductionsSyndicate · Jun 12, 2011 at 07:56 PM
Say there were five cars. Make a static variable thats 5. Then whenever a car dies subtract one from that number. When the number gets to zero you can have the scene fade to a loading screen and load the new level. Or you can make a object appear to send you to the next level in the same way.
The script to fade is here: http://www.unifycommunity.com/wiki/index.php?title=FadeInOut
public var car : Transform;
function OnCollisionEnter(col: Collision){
if(col.gameObject.name == "computer car moving"){
Destroy(col.gameObject);
}
}
is that correct FutchProductionsSyndicate?
Yeah, that looks like it should work, but whats the public var doing there?
Answer by sdsanft · Dec 23, 2014 at 04:43 AM
Create a script that triggers the next level to load when all the cars are destroyed. Create two variables for the number of cars and the number of cars destroyed and set the destroyed cars variable to zero. Every time a car is destroyed, increment that variable and when it is equal to the total number of cars (signifying all the cars are destroyed) load the next level using Application.LoadLevel.
Your answer
Follow this Question
Related Questions
When player collides with object load next level 1 Answer
Android Button Text 1 Answer
How to reduce time of instantiating a prefab that contains many objects/components in it. 1 Answer
Restart game script. 1 Answer
Random level select 1 Answer