Quantcast
Channel: Questions in topic: "time trial"
Viewing all articles
Browse latest Browse all 8

I need help in comparing the chronometer with a record time in my racing game

$
0
0
Hello, for anyone who can help me thank you so much for this, I have a problem comparing a record time in my game, It's a racing game, what I would like to do is to use two values to compare with the timer, for example the track record time is 3: 35.0 minutes, I've made a script responsible for the time and one for the record, in the TrackRecord script I put two Variables Statics "timeRecordMinutes" = 3 and "timeRecordSeconds" = 25, in the Timer script I did almost the same thing, only it is a timer are numbers On the move please see my script: using UnityEngine; using UnityEngine.UI; using System.Collections; public class Timer : MonoBehaviour { public TextMesh contadorDeTempo; private float inicioDoTempo; // Here will start counting the time public static bool Finish = false; // This bool will cause the timer to stop when true. public static int minutos; // Will count the minutes public static int segundos; // Will count from seconds. public static float t; // Use this for initialization void Start () { inicioDoTempo = Time.time; } // Update is called once per frame void Update () { if (Finish) return; t = Time.time - inicioDoTempo; minutos = ((int) t / 60); segundos = ((int) t % 60); contadorDeTempo.text = "Time: " + minutos + ":" + segundos; // Will display the time on the screen. } public void Finished(){ Finish = true; } } Now the script of the CP_LapSystem is what is responsible for counting the laps and that should compare the current time with record time: using UnityEngine; using System.Collections; public class CP_LapsSystem : MonoBehaviour { public static Transform CarPlayer; public WheelCollider[] pneus = new WheelCollider[4]; public Transform UltimoCheckpoint; public int númeroDeCheckpoints; public string tempoRecorde = "3:25.0"; // Use this for initialization void Start () { CarPlayer = transform.Find("Player"); } void OnTriggerEnter(Collider other){ if (!other.CompareTag ("Player") && other.CompareTag("AIGT")) return; if (transform == Checkpoint.CheckA [Checkpoint.checkPointAtual].transform) { // Vai checar se nós passamos em todas as matrizes do Checkpoints para... if(Checkpoint.checkPointAtual +1 Checkpoint.LimiteDeVoltas) { FordGT2016.torqueMaximo = 0; Timer.Finish = true; if (TrackRecord.tempoRecordeMinutos > Timer.minutos && TrackRecord.tempoRecordeSegundos > Timer.segundos) { ().text = "Finished!" + " You Win!, You beat the time Record!"; }else{ Camera.main.GetComponentInChildren ().text = "Finished!" + " You lose!, You don't beat the time Record try again!"; } } else { pneus [0].brakeTorque = 0; pneus [1].brakeTorque = 0; pneus [2].brakeTorque = 0; pneus [3].brakeTorque = 0; GetComponentInChildren().text = "Running"; Camera.main.GetComponentInChildren ().text = " Laps : " + (Checkpoint.voltaAtual) + "/ " + (Checkpoint.LimiteDeVoltas) + " Time Record : " + (tempoRecorde); Timer.Finish = false; } if (Checkpoint.voltaAtual == 2) { GetComponentInChildren ().text = "Final Lap!"; } if (Checkpoint.voltaAtual == 3) { GetComponentInChildren().text = " Finish"; } } } } } I wanted to compare the time that is running in the timer but every time I finish the race and I can beat the record always comes the same message "Finished! You lose !, You do not beat the time Record try again!", can someone help me please? `

Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images