- Home /
How do I stop a stopwatch/timer and display it on the end screen when the player hits the last Box Collider?,How do I stop the timer and display it on a new scene when the player hits the last BoxCollider2D?
I am making a game with my friend for a school project and we are trying to make a platformer that is just a game for the fastest time. This is our first game and we would like to display the text on the end screen and basically make a leader board for personal best times. As you can see in the script, then we already have an "if" statement for isFinished, but we dont know how to make it so it ends when it hits the last box collider.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using UnityEngine.UI;
public class Countdown : MonoBehaviour
{
public bool isFinished;
public float timeStart;
public Text textBox;
// Start is called before the first frame update
void Start()
{
textBox.text = timeStart.ToString("F2");
}
// Update is called once per frame
void Update()
{
if (!isFinished)
{
timeStart += Time.deltaTime;
textBox.text = Convert.ToString(timeStart);
textBox.text = timeStart.ToString("F2");
// Makes stopwatch only update if isFinished is false.
}
}
}
,I am making a game with my friend for a school project and we are trying to make a platformer that is just a game for the fastest time. This is our first game and we would like to display the text on the end screen and basically make a leader board for personal best times. This is our stopwatch script, it is placed on our main camera. As you can see we already added an if isFinished statement, but we dont know how to make it stop when it hits the Box Collider. Is displaying it just as easy as putting it on a new scene and when the player wins and goes to the new scene it still loads with the time(because the win screen is a new scene)?
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using UnityEngine.UI;
public class Countdown : MonoBehaviour
{
public bool isFinished;
public float timeStart;
public Text textBox;
// Start is called before the first frame update
void Start()
{
textBox.text = timeStart.ToString("F2");
}
// Update is called once per frame
void Update()
{
if (!isFinished)
{
timeStart += Time.deltaTime;
textBox.text = Convert.ToString(timeStart);
textBox.text = timeStart.ToString("F2");
// Makes stopwatch only update if isFinished is false.
}
}
}
Your answer
Follow this Question
Related Questions
Timer jitters? SOLVED 0 Answers
How can I flip only my 'Player' gameobject, and l leave it's child object alone? 2 Answers
animation script for 2D platformer issue 2 Answers
2D EndlessRunner Spike Placing 0 Answers