Pause Timer on Trigger

Hello,

A brief of the game;
*The game level is complete when the ball goes through the hole.

  • I have been able to make the Level Complete UI appear when the trigger event occurs, however, the timer at the top keeps on counting.

I need some help to achieve the following;

  • I want the timer to stop at the exact time in which the ball hits the trigger ( note that the trigger is positioned at the opening situated at the bottom right part of the screen)

But the trigger scripts and time control scripts are in different game objects so its hard to follow online tutorials.

I have attached copies of the scripts and screenshot of the game-play at Start and End (when ball hits trigger).

Any contributions and comment are highly appreciated.

Thank you

5125937–506522–CountDownScript.pdf (41.3 KB)
5125937–506525–Levelwonappear.pdf (39.7 KB)


Hi @whalewale

Look into events and delegates. They are not Unity specific things, but C# language feature. Although Unity has many Learn section tutorials where you can see how to use them.

Unity also has its own version of these, called UnityEvents (which just adds UI in inspector, so you can add event listeners from Inspector like you can for UI buttons and such):

You basically have an event, and then your interested object will subscribe to listen for game won event (or whatever), and when this event is fired, listening party can do whatever he wants (like stop the clock, show game over screen).

I will look into them . Thanks

I was able to achieve pausing the timer by doing this;

public class CountDownScript : MonoBehaviour
{
public GameObject m_canvas;

}
void Update()
// LEVEL WON Check if Levelwoncanvas has been Activated
{
if (m_canvas.gameObject.activeSelf == true)

{
timer += Time.deltaTime;
}
}

Also how can I make the time format be in Minutes:Seconds. Its currently in Seconds : Micro seconds

I think you should ask this in a separate question, as it is something else than your original question.