- Home /
One Action/Mission at a time
Hi there, I have a currently working code with a timer that starts and finishes on trigger and on collision respectively. But I am having trouble coding up how to make sure the character has to finish one mission to move on to the next.how will I go about coding this. So basically finishing HasMission then only being able to activate HasMission1 many thanks in advance
if (Physics.Raycast (transform.position,dwn,hit, .5)) {
var t:Timer;
if(hit.collider.gameObject.tag=="HasMission"){
Debug.Log("has mission");
if(!showingMission){
showingMission=true;
t=GameObject.Find("Timer").GetComponent("Timer") as Timer;
t.startTimer();
}
}else if(hit.collider.gameObject.tag=="EndMission"){
}
}
if (Physics.Raycast (transform.position,dwn,hit, .5)) {
if(hit.collider.gameObject.tag=="HasMission1"){
Debug.Log("has mission");
if(!showingMission2){
showingMission2=true;
t=GameObject.Find("Timer1").GetComponent("Timer") as Timer;
t.startTimer();
}
}else if(hit.collider.gameObject.tag=="EndMission1"){
}
}
Answer by robertbu · May 26, 2013 at 06:50 AM
I'm not completely sure what you are doing here, but I think you do something like this:
if (GameObject.FindObjectWithTag("EndMission") && Physics.Raycast (transform.position,dwn,hit, .5)) {
So the second Physics.Raycast would only be reached if showingMission was true (i.e. the first mission is started) and there is no game object with the "HasMission" tag.
Wouldn't it make sense to make sure the character is unable to start next mission until End$$anonymous$$ission has happened and stopped the timer?..(don't worry about the timer, It's working fine).. and that bit of coding doesn't seem to work, it disables the coding. I am just unsure about how to code this up.. :/
So I changed the logic to use "End$$anonymous$$ission". I don't see anything here stopping the timer nor do I know how to check it based on the code above.
This is the timer script that I am currently using and works just fine.
private var doTimer:boolean;
private var startTime:float;
private var elapsedTime:float;
function Start () {
doTimer=false;
}
function Update () {
if(doTimer){
elapsedTime=Time.time-startTime;
GetComponent(GUIText).text = (elapsedTime).ToString("f2");
}
}
function startTimer(){
startTime=Time.time;
doTimer=true;
}
function stopTimer(){
doTimer=false;
return parseInt(elapsedTime);
}
and this is the End$$anonymous$$ission attached to one of the Tiles #pragma strict
function Start () {
}
function Update () {
}
function OnCollisionEnter(o:Collision){
if(o.gameObject.name=="EndBox"){
var charScript:$$anonymous$$ovewithRaycast=GameObject.Find("CharContainer").GetComponent("$$anonymous$$ovewithRaycast") as $$anonymous$$ovewithRaycast;
if(charScript.isShowing$$anonymous$$ission()){
var t:Timer;
t=GameObject.Find("Timer").GetComponent("Timer") as Timer;
var timeTaken:int=t.stopTimer();
Debug.Log("time taken was "+timeTaken);
}
}
}
Now what do you think? So, everything in the game functions without flaws, but I want to order the flow of missions..
Your answer
![](https://koobas.hobune.stream/wayback/20220613102930im_/https://answers.unity.com/themes/thub/images/avi.jpg)