So I’m trying to make a game where it records how long you last using a stopwatch. I searched all over the internet and I could not figure out how to combine my respawn or death script together with any stopwatch script! Here is my code for the respawn script that I place in the player, anyone smart enough to figure out how my respawn script works can you help me find a Stopwatch script and combine it together to Restart the Stopwatch when the player Respawns and Records it to a Highscore (and if you can make it save as a local file inside the game forever so when the player reopens the game it is there)
using UnityEngine;
using System.Collections;
public class respawn : MonoBehaviour
{
public float threshold;
void FixedUpdate()
{
if (transform.position.y < threshold)
transform.position = new Vector3(0, 0, 0);
}
}
Note: I an using C#
using UnityEngine;
using System.Collections;
public class respawn : MonoBehaviour
{
public float threshold;
float initialTime;
void Start()
{
initialTime = Time.time;
if(PlayerPrefs.HasKey("HighscoreTime")==false)
{
PlayerPrefs.SetFloat("HighscoreTime",0);
}
}
void FixedUpdate()
{
if (transform.position.y < threshold)//assuming this where you respawn
{
float TimeTaken = Time.time - initialTime;
if ((TimeTaken)>PlayerPrefs.GetFloat("HighscoreTime"))//">" or "<" I'm not sure.. If the highscore is the highest time taken then ">" is right , otherwise change it to "<"
{
print("Highscore time is " + TimeTaken);
PlayerPrefs.SetFloat("HighscoreTime",TimeTaken);
}
transform.position = new Vector3(0, 0, 0);
initialTime = Time.time;//Fixed it
}
}
}
You don’t have to save it in a local file thanks to PlayerPrefs.
I hope you understand the code I added its pretty intuitive… I haven’t really tested it but you should be able to fix any errors if any.
I think if you watch brackyes how to make a doge block game you will figure it out
Online Stopwatch Countdown Timer
September 28, 2020
It’s a really nice tool so what you can do here by the timeline -
Stopwatch slash
countdown timer is that you can put this into full-screen mode so
you got down here in the bottom and use the timer in full-screen
mode so I’m gonna go ahead