Load a certain level depending on where objects are placed.
Hi. I'm making a sort of tycoon game, I have got the basic drag and drop feature. When a button is pressed, I want it to load a level depending on how many of each object there is. For instance I have ads, talk shows and music, if there is a right balance of them load a certain level, if there is too many ads then load another etc... I have the basic code for loading A level but a specific one.
#pragma strict
public var Level = "2";
function LoadLevel(){
Application.LoadLevel(Level);
}
so yeah I just need it to choose a level depending on strings
explain more you asked :
depending on where objects are placed.
& explained :
depending on how many of each object there is.
so positions or quantity ?
Hey, sorry I wasn't clear. I mean the game is UI. The player drags ui objects on the screen. I want when a button is pressed to load a level depending the the type of UI object which is music, ads or talk shows.
Answer by Ali-hatem · Mar 20, 2016 at 12:20 PM
c# so now tag the UI elements in inspector & make sure tags are same as you test in script :
public GameObject [] Music;
public GameObject [] Ads;
public GameObject [] Shows;
void Update(){
Music = GameObject.FindGameObjectsWithTag ("music");
Ads = GameObject.FindGameObjectsWithTag ("ads");
Shows = GameObject.FindGameObjectsWithTag ("shows");
}
public void ChoesLevel(){
//this test which object have the larger amount than others if you want certain NUMBER test only the array length like that if(Music.Length == 5) .
if (Music.Length > Ads.Length && Music.Length > Shows.Length) {
print ("music :" + Music.Length);
} else if (Ads.Length > Music.Length && Ads.Length > Shows.Length) {
print ("ads :" + Ads.Length);
} else if (Shows.Length > Music.Length && Shows.Length > Ads.Length) {
print ("show :" + Shows.Length);
} else {
print ("there is no one type is biger than others");
}
}
Hey. Thanks so much for the code - but I don't think you understand, probably due to my descriptive skills ;p
The idea is when there is a certain NU$$anonymous$$BER of ads, music or talk shows then load the scene depending on that number.
Sorry for confusion ;[
i was thinking you might mean this but i want to make sure now my brain is freezing i been answering & commenting all the day & i will tray something tomorrow even it looks tricky if now i understand you you want to calculate which type is grater than others then open that type scene.
now i have edited the code it will test which object have the larger amount than others just in case you want that if you want certain NU$$anonymous$$BER easy just test the array length like that if($$anonymous$$usic.Length == YournNmber) .