2 questions

so im using this script…that states that if i collide with a game object the other level loads and adds +1 to the passed levels in another scene…the thing is that i want for that number to get only up to 10 and if i play the levels again and pass them again…it keeps adding +1…here is the script

var levelToLoad: int;
var WaitTime = 3;
var Sound : AudioSource;




function OnTriggerEnter(hit : Collider){
	if(hit.gameObject.tag == "Player"){
	Sound.Play();
	StartCoroutine(WaitAndLoad(WaitTime));

	
	}
}

function WaitAndLoad(t){
yield WaitForSeconds(t);
Application.LoadLevel(levelToLoad);
passedLevels = LevelsPassed.level+=1;
}

here is the “LevelsPassed” script

var MyFont : Font;
static var level = 0;
		

function OnGUI(){
GUI.contentColor = Color.red;
GUI.skin.font = MyFont;
GUI.Label (Rect (300,10,150,150), (level+"/10"));
}

and this is my other question,
how would i make a script that if i already passed a level…it will not add +1 again to the "LevelsPassed"script…because i also have another script that enables a button that loads a scene…in order to do that the LevelsPassed # has to be equal to 10…so in other words…if i would pass level 1 (easiest) 10 times the button would be activated and i could go to the level without having to pass the other levels…i know this is alot…but i tried o explain it really well so that someone could help me :slight_smile:
here is the script that enables the button
“ArrowEnabled”

var Arrow : Transform;

if ( LevelsPassed.level < 9) {
Arrow.active =false;
}
if ( LevelsPassed.level > 9) {
Arrow.active =true;
}

thank u so much :)…if some of you know how to solve any of this please tell me :)…i would really appreciate it…i can’t continue my project because of this :/…thanks! -Goatria

passedLevels = (LevelsPassed.level+=1)%10; is probably what you are after. Then when you complete level 9 it will go back to zero.

or do you want it to still say 10 all the time?
Well then you can restrict the value by:

if(passedLevels<0)
passedLevels = (LevelsPassed.level+=1);

with no else statement.

For question 2:
well it seems to be the same as question 1 really.

what u told me didn’t work…hmmm…what could it be?..also…i think you didn’t get my second question…what i ment was that if i already got the +1 from that level…the 2nd time i playn it…i wont get the +1 again after i pass it…only the 1st time…so that way i have to pass all 10 levels to unlock the next 10 levels u know wh mean? :)…it was really nice from you to pass by and read all my loooong question…if you have any other idea on how to fix this please tell me :slight_smile: thanks once again :smile: - Goatria

sorry my line lost the 1
if(passedLevels<10)
passedLevels = (LevelsPassed.level+=1);

so if the passedLevels are less than 10 then you are allowed to add another.

So you want like steps of 10 levels. Complete 10, get 10 more? Here actually I would call do some other system where you number them from 1->20(or 30 or how many you want). Then when you want to name them you do level%10+1 which means the value will be from 1 to 10. It all depends on how you want the GUI to look.

You can of cause also have another variable that keeps track of how many 10s of levels you have completed so you keep all above but add,

stagesOfTenCompleted = 0; Then when youc omplete the 10th level you increment and reset levelsPassed to 0, and using the stagesOfTenCompleted you can calculate which level to load(by Application.LoadLevel(levelToLoad); where levelToLoad is (stagesOfTenCompleted*10+levelsPassed+1) or something like that.

i fixed the 1st part…now i need to know how to get +1 to the “LevelsPassed” script only with the levels i havent passed :)…any help would be greatly appreciated :slight_smile:

how do you mean, can you create an example?

like for example…if i pass level 1,The LevelsPassed script would be +=1…but the second time i pass level 1 again the LevelsPassed will not increase…because if i keep passing level 1…the LevelsPassed script will get to 10 and it will enable the button that takes you to the next set of levels you know?..hehe…its hard to explain

I see. Where do you have the number of the level you are currently playing. because a change like this would help:

if(passedLevels<10 (currentlevel>passedLevels))
passedLevels = (LevelsPassed.level+=1);

Then only if the current level number(counting from 1) is higher than the amount of passed levels we are allowed to get a new level upon completion.

what can i replace with “currentlevel”? it says "Unknown identifier: “currentLevel”

yes that is just a name I came up with. somewhere within each level you should have the number of the current level.

huh?..hehe sorry i don’t get it…sorry if im frustrating u…but i think were getting there…i just need to know what to put instead of current level…i tried “Application.LoadeLevelName” but it didn’t work :confused:

levelToLoad-1 is the value you want I think, found in the topmost script.

hmmm…i think were not speaking the same language XD…what language do u code?..im using javascript…

I normally go c#

but I am referring to this script:

var levelToLoad: int;
var WaitTime = 3;
var Sound : AudioSource;




function OnTriggerEnter(hit : Collider){
	if(hit.gameObject.tag == "Player"){
	Sound.Play();
	StartCoroutine(WaitAndLoad(WaitTime));

	
	}
}

function WaitAndLoad(t){
yield WaitForSeconds(t);
Application.LoadLevel(levelToLoad);
passedLevels = LevelsPassed.level+=1;
}

The levelToLoad , but decreased by one so (levelToLoad-1) is the value you want so

if(passedLevels<10 ((levelToLoad-1)>passedLevels))
passedLevels = (LevelsPassed.level+=1);

thats what i did…but i dont get the last part XD…

help anyone?