- Home /
Question by
Davidbillmanoy · Jun 20, 2021 at 07:34 AM ·
racingracing game
Lap Counter Bug
Hello! I have a bug in the UI Script. After I completed the first lap, it's stuck in the first lap, and after I completed the third lap, the race is finished. Anybody can help me with this bug?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIScript : MonoBehaviour
{
GameObject Player;
public GameObject missedCheckpointText;
public GameObject pauseGameMenu;
public Text positionText;
public Text lapText;
Checkpoints checkpoint;
public Text finalPosText;
public Text earnedCoinsText;
RaceManager raceManager;
void Start()
{
Player = GameObject.FindGameObjectWithTag("Player");
checkpoint = Player.GetComponent<Checkpoints>();
}
void Update()
{
if(checkpoint.checkPoint == 0 )
{
lapText.GetComponent<Text>().text = "Lap: " + checkpoint.lap + "/" + raceManager.maxLaps;
}
positionText.GetComponent<Text>().text = "Position: " + CalculatePositions.getPositions(Player.name);
if (Player.GetComponent<Checkpoints>().missed==true)
{
StartCoroutine(showmissedCheckpointtext());
Player.GetComponent<Checkpoints>().missed = false;
}
if(Input.GetKeyDown(KeyCode.Escape))
{
PauseGame();
}
}
IEnumerator showmissedCheckpointtext()
{
missedCheckpointText.SetActive(true);
yield return new WaitForSeconds(2);
missedCheckpointText.SetActive(false);
}
public void PauseGame()
{
pauseGameMenu.SetActive(true);
Time.timeScale = 0;
}
public void ResumeGame()
{
Debug.Log("Btn Clicked");
Time.timeScale = 1;
pauseGameMenu.SetActive(false);
}
public void showFinalPos()
{
if(CalculatePositions.getPositions(Player.name)=="1st")
{
int currentCoins = PlayerPrefs.GetInt("coins");
PlayerPrefs.SetInt("coins", currentCoins + 750);
earnedCoinsText.text = "You earned 750 coins";
}
else
{
int currentCoins = PlayerPrefs.GetInt("coins");
PlayerPrefs.SetInt("coins", currentCoins + 100);
earnedCoinsText.text = "You earned 100 coins";
}
finalPosText.text = CalculatePositions.getPositions(Player.name);
}
}
Comment
Your answer
Follow this Question
Related Questions
Car exhaust Flame in unity 1 Answer
Car Tutorial adding other cars 1 Answer
Universal Render Pipeline motion blur blurres car 1 Answer
How do I make the winning racer get a text saying Congrats? 1 Answer
in a multiplayer racing game how would you determine which car crossed the finish line first? 1 Answer