- Home /
Sequential Missions
Hi there guys, I have here two bits of coding, the first one is working and is working how it's supposed to, but the second doesn't. Is there something wrong with the 2nd one's coding?
First Code ( Code that Works )
var t:Timer;
//this new code should mean you don't need HasMission1, HasMission2 etc
if (Physics.Raycast (transform.position,dwn,hit, .5))
if(hit.collider.gameObject.tag=="HasMission"){
Debug.Log("has mission");
if(!showingMission){
//ok we are not yet showing a mission, but has the previous one been completed?
var ms:MissionStarter=hit.collider.gameObject.GetComponent("MissionStarter") as MissionStarter;
var thisMission=ms.myMissionID;
//if this is the first mission or they have completed the previous mission
if(thisMission==1 || Globals.hasCompletedMission(thisMission-1)){
//proceed as normal
Globals.currentMission=thisMission;
showingMission=true;
t=GameObject.Find("Timer").GetComponent("Timer") as Timer;
t.startTimer();
}
}else if(hit.collider.gameObject.tag=="EndMission"){
//is this required?
}
}
and the bit that doesn't work
if (Physics.Raycast (transform.position,dwn,hit, .5))
if(hit.collider.gameObject.tag=="HasMission1"){
Debug.Log("has mission");
if(!showingMission){
//ok we are not yet showing a mission, but has the previous one been completed?
//if this is the first mission or they have completed the previous mission
if(thisMission==2 || Globals.hasCompletedMission(thisMission+1)){
//proceed as normal
Globals.currentMission=thisMission;
showingMission=true;
t=GameObject.Find("Timer").GetComponent("Timer") as Timer;
t.startTimer();
}
}else if(hit.collider.gameObject.tag=="EndMission1"){
//is this required?
}
}
last but not least the Globals the scripts are linked to
static var currentMission:int=-1;
static var completedMissions:Array=new Array();
static function hasCompletedMission(which:int){
for(var i:int=0;i<completedMissions.length;i++){
if(completedMissions[i]==which){
return true;
}
}
return false;
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613103049im_/https://answers.unity.com/themes/thub/images/avi.jpg)