However, when I exit the trigger I want the countdown to stop and reset. So I have a reset function which resets the counter:
function ResetCount()
{
iTween.FadeTo(gameObject, 0, 0.1);
GetComponent(TextMesh).text = "3";
}
Now the problem I have is that I need this ResetCount() to "interrupt" the countdown so that when I exit the trigger the countdown stops. However, currently the Countdown() function continues even after the trigger has been exited. I have tried the following in my exit trigger but to no ammends:
Any ideas on how I can get the Countdown function to stop when the trigger is exited - even if it is in the middle of running?
That was just for the next trigger enter - however even when removing that line to make it true again the behaviour is the same. Thanks for the link. I'll take a look although I would like to figure this out too :D
Maybe a daft question but have you tried ontrigger stay?or putting a boolean at the beginning of countdown which turns off when ontrigger exit is called. And this may also be a daft question but I cant understand why you're getting components in the ontrigger exit function? surely it would be in the same script and you could then easily disable it? eg
function OnTriggerEnter()
{
Countdown();
}
function OnTriggerExit()
{
ResetCount();
}
function Countdown ()
{
if (CountdownHasBeenCalled == false)
{
//itween stuff
}
}
function ResetCount()
{
CountdownHasBeenCalled = true;
}
The problem is even if I do the above the iTween stuff gets called in its entirity since the if check is only called at the start of the code. The same happens if I use a boolean with the OnTriggerStay function. I have a decent workaround now which I'll post as an answer for people to re-use if they wish. It's a little messy but it get's the job done!
The variable "counting" is set to true in the TriggerEnter and false in the TriggerExit (I could use the TriggerStay but this also works). So basically I:
Set the number
Fade it in
Fade it out
Check if we are still counting
If we are then do the same for the next number - if not then we break out of the code (I also reset the counter in the trigger exit)
That was just for the next trigger enter - however even when removing that line to make it true again the behaviour is the same. Thanks for the link. I'll take a look although I would like to figure this out too :D
– GesterX