when the ball collides with the Goal collider it should cancel the DisplayNoGoal()
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == "Ball")
{
CancelInvoke("DisplayNoGoal");// this function is called from here when person does in fact get a goal..to cancel the DisplayNoGoal()
}
}
// when the ball is kicked the Invoke function executes as following.
if(countBalls.ballcount==1){
Invoke( "DisplayNoGoal", 3.0);
}
function DisplayNoGoal()
{
print("goal missed");
goalMissed.enabled = true;
}
the problem here is when the person kicks the ball the invoke function executes and delay for 3 seconds but even if the goal is done by the person the invoke function is not getting canceled...
Since your if statement only checks if ballcount is equal to 1, then every time OnGUI gets called (which is fairly often) and there’s a ball on the court, it’ll re-invoke “DisplayNoGoal”. It’s hard to give a solution without looking at the rest of your code, but there are two things which should work. Either add a boolean flag when you call CancelInvoke(“DisplayNoGoal”), and use that refer to that flag in your if statement like this: