I don’t know how to script if the 4 objects in the scene did not destroy then he did not proceed to the next level of the game.
-i have 4 object in my game play the player then to destroy all the 4 objects to go in the next level. how is it? please help me.
2 Answers
2Add a function OnDestroy( ) to each one of your 4 objects. In this function, you'll simply turn a boolean variable to TRUE. When all the four variables are TRUE, you can access next level. What I mean is something like this:
(NOTE: the following code is untested, and its purpose is just to give you a general idea on this)
This is a global variable, and it'll contains all the flags for checking the destructions:
var flags : boolean[] = new boolean[4];
This script is attached to each one of the 4 objects (with different "object_index"!!!), and this will be activated if the object is destroied:
var object_index = 1; //object_index's value is 1 for the 1° object, 2 for the 2° one,...,4 for the 4° one
function OnDestroy(){
flags[object_index] = 1;
}
This function has to be called from the Update() of the object in which you check for the level changing:
function Update(){
//...
Check_next_level;
//...
}
function Check_next_level(){
going_to_next_level = 1;
for (var i=1; i++; i<5){
if (flags *== 0){*
*going_to_next_level = 0;*
*break;*
*}*
*}*
*if (going_to_next_level){*
*level_index++; //You have to declare this outside, and use it to mantain the reference to the actual level*
*Application.LoadLevel(level_index);*
*}*
*}*
*```*
flags is an array and flags[object_index] is equal to 1 if that object has been destroied (so, flags[2]=1 means that the 2° object has been destroied). And no, they are not "in one file": the first script has to be attached to each one of the 4 objects; the second one, it depends by the point in which you check for the next level.
– BiGsimply add Application.loadedLevel ("levelName");
Before the Destroy action not After it
sure thing, mate: http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)?highlight=newbie+javascript
– by0log1c